diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index 278e98ced..a3a3420de 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -1,4 +1,3 @@ docker: - digest: sha256:c3eae37a355402067b97cbeb6f5a7d2dd87aecfd064aeb2d2ea0bde40778cf68 - image: gcr.io/repo-automation-bots/owlbot-nodejs:latest - + image: gcr.io/repo-automation-bots/owlbot-nodejs:latest + digest: sha256:f93bb861d6f12574437bb9aee426b71eafd63b419669ff0ed029f4b7e7162e3f diff --git a/.github/generated-files-bot.yml b/.github/generated-files-bot.yml new file mode 100644 index 000000000..1b3ef1c78 --- /dev/null +++ b/.github/generated-files-bot.yml @@ -0,0 +1,13 @@ +generatedFiles: +- path: '.kokoro/**' + message: '`.kokoro` files are templated and should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' +- path: '.github/CODEOWNERS' + message: 'CODEOWNERS should instead be modified via the `codeowner_team` property in .repo-metadata.json' +- path: '.github/workflows/**' + message: '`.github/workflows` (GitHub Actions) should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' +- path: '.github/generated-files-bot.+(yml|yaml)' + message: '`.github/generated-files-bot.(yml|yaml)` should be updated in [`synthtool`](https://github.com/googleapis/synthtool)' +- path: 'README.md' + message: '`README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/master/.readme-partials.yaml' +- path: 'samples/README.md' + message: '`samples/README.md` is managed by [`synthtool`](https://github.com/googleapis/synthtool). However, a partials file can be used to update the README, e.g.: https://github.com/googleapis/nodejs-storage/blob/master/.readme-partials.yaml' diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3df11de40..891c92531 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,7 +1,7 @@ on: push: branches: - - $default-branch + - master pull_request: name: ci jobs: diff --git a/protos/protos.d.ts b/protos/protos.d.ts index 2bc15192a..53b30b43d 100644 --- a/protos/protos.d.ts +++ b/protos/protos.d.ts @@ -4891,7 +4891,7 @@ export namespace google { public time?: (google.protobuf.ITimestamp|null); /** SeekRequest snapshot. */ - public snapshot: string; + public snapshot?: (string|null); /** SeekRequest target. */ public target?: ("time"|"snapshot"); @@ -6024,7 +6024,7 @@ export namespace google { public parent: string; /** ValidateMessageRequest name. */ - public name: string; + public name?: (string|null); /** ValidateMessageRequest schema. */ public schema?: (google.pubsub.v1.ISchema|null); @@ -6348,19 +6348,19 @@ export namespace google { public selector: string; /** HttpRule get. */ - public get: string; + public get?: (string|null); /** HttpRule put. */ - public put: string; + public put?: (string|null); /** HttpRule post. */ - public post: string; + public post?: (string|null); /** HttpRule delete. */ - public delete: string; + public delete?: (string|null); /** HttpRule patch. */ - public patch: string; + public patch?: (string|null); /** HttpRule custom. */ public custom?: (google.api.ICustomHttpPattern|null); diff --git a/protos/protos.js b/protos/protos.js index 2d3c27e71..9290302f9 100644 --- a/protos/protos.js +++ b/protos/protos.js @@ -11168,11 +11168,11 @@ /** * SeekRequest snapshot. - * @member {string} snapshot + * @member {string|null|undefined} snapshot * @memberof google.pubsub.v1.SeekRequest * @instance */ - SeekRequest.prototype.snapshot = ""; + SeekRequest.prototype.snapshot = null; // OneOf field names bound to virtual getters and setters var $oneOfFields; @@ -13629,11 +13629,11 @@ /** * ValidateMessageRequest name. - * @member {string} name + * @member {string|null|undefined} name * @memberof google.pubsub.v1.ValidateMessageRequest * @instance */ - ValidateMessageRequest.prototype.name = ""; + ValidateMessageRequest.prototype.name = null; /** * ValidateMessageRequest schema. @@ -14391,43 +14391,43 @@ /** * HttpRule get. - * @member {string} get + * @member {string|null|undefined} get * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.get = ""; + HttpRule.prototype.get = null; /** * HttpRule put. - * @member {string} put + * @member {string|null|undefined} put * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.put = ""; + HttpRule.prototype.put = null; /** * HttpRule post. - * @member {string} post + * @member {string|null|undefined} post * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.post = ""; + HttpRule.prototype.post = null; /** * HttpRule delete. - * @member {string} delete + * @member {string|null|undefined} delete * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype["delete"] = ""; + HttpRule.prototype["delete"] = null; /** * HttpRule patch. - * @member {string} patch + * @member {string|null|undefined} patch * @memberof google.api.HttpRule * @instance */ - HttpRule.prototype.patch = ""; + HttpRule.prototype.patch = null; /** * HttpRule custom. diff --git a/src/iam.ts b/src/iam.ts index 9dbfb2dc8..b49092812 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -379,13 +379,12 @@ export class IAM { } const availablePermissions = arrify(resp!.permissions!); - const permissionHash: IamPermissionsMap = (permissions as string[]).reduce( - (acc, permission) => { - acc[permission] = availablePermissions.indexOf(permission) > -1; - return acc; - }, - {} as {[key: string]: boolean} - ); + const permissionHash: IamPermissionsMap = ( + permissions as string[] + ).reduce((acc, permission) => { + acc[permission] = availablePermissions.indexOf(permission) > -1; + return acc; + }, {} as {[key: string]: boolean}); callback!(null, permissionHash, resp!); } ); diff --git a/src/publisher/index.ts b/src/publisher/index.ts index a567232dd..914617b28 100644 --- a/src/publisher/index.ts +++ b/src/publisher/index.ts @@ -245,12 +245,8 @@ export class Publisher { setOptions(options = {} as PublishOptions): void { const defaults = this.getOptionDefaults(); - const { - batching, - gaxOpts, - messageOrdering, - enableOpenTelemetryTracing, - } = extend(true, defaults, options); + const {batching, gaxOpts, messageOrdering, enableOpenTelemetryTracing} = + extend(true, defaults, options); this.settings = { batching: { @@ -325,9 +321,8 @@ export class Publisher { message.attributes = {}; } - message.attributes[ - 'googclient_OpenTelemetrySpanContext' - ] = JSON.stringify(span.context()); + message.attributes['googclient_OpenTelemetrySpanContext'] = + JSON.stringify(span.context()); } return span; diff --git a/src/pubsub.ts b/src/pubsub.ts index 94f033911..9e8d95886 100644 --- a/src/pubsub.ts +++ b/src/pubsub.ts @@ -664,9 +664,8 @@ export class PubSub { // If this looks like a GCP URL of some kind, don't go into emulator // mode. Otherwise, supply a fake SSL provider so a real cert isn't // required for running the emulator. - const officialUrlMatch = this.options.servicePath!.endsWith( - '.googleapis.com' - ); + const officialUrlMatch = + this.options.servicePath!.endsWith('.googleapis.com'); if (!officialUrlMatch) { const grpcInstance = this.options.grpc || gax.grpc; this.options.sslCreds = grpcInstance.credentials.createInsecure(); diff --git a/src/subscriber.ts b/src/subscriber.ts index bff1bb98d..0c236ae73 100644 --- a/src/subscriber.ts +++ b/src/subscriber.ts @@ -429,9 +429,8 @@ export class Subscriber extends EventEmitter { options.streamingOptions = {} as MessageStreamOptions; } - const { - maxStreams = defaultOptions.subscription.maxStreams, - } = options.streamingOptions; + const {maxStreams = defaultOptions.subscription.maxStreams} = + options.streamingOptions; options.streamingOptions.maxStreams = Math.min( maxStreams, this.maxMessages @@ -471,8 +470,9 @@ export class Subscriber extends EventEmitter { [MessagingAttribute.MESSAGING_DESTINATION_KIND]: 'topic', [MessagingAttribute.MESSAGING_MESSAGE_ID]: message.id, [MessagingAttribute.MESSAGING_PROTOCOL]: 'pubsub', - [MessagingAttribute.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES]: (message.data as Buffer) - .length, + [MessagingAttribute.MESSAGING_MESSAGE_PAYLOAD_SIZE_BYTES]: ( + message.data as Buffer + ).length, // Not in Opentelemetry semantic convention but mimics naming 'messaging.pubsub.received_at': message.received, 'messaging.pubsub.acknowlege_id': message.ackId, diff --git a/src/topic.ts b/src/topic.ts index 09d0dea1f..4e82a0f3e 100644 --- a/src/topic.ts +++ b/src/topic.ts @@ -573,12 +573,13 @@ export class Topic { const options = typeof optsOrCallback === 'object' ? optsOrCallback : {}; callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback; - const reqOpts: google.pubsub.v1.IListTopicSubscriptionsRequest = Object.assign( - { - topic: this.name, - }, - options as SubscriptionOptions - ); + const reqOpts: google.pubsub.v1.IListTopicSubscriptionsRequest = + Object.assign( + { + topic: this.name, + }, + options as SubscriptionOptions + ); delete (reqOpts as PageOptions).gaxOpts; delete (reqOpts as PageOptions).autoPaginate; diff --git a/src/v1/publisher_client.ts b/src/v1/publisher_client.ts index b2c771d48..af450c13d 100644 --- a/src/v1/publisher_client.ts +++ b/src/v1/publisher_client.ts @@ -269,13 +269,14 @@ export class PublisherClient { ]; for (const methodName of publisherStubMethods) { const callPromise = this.publisherStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, + stub => + (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, (err: Error | null | undefined) => () => { throw err; } @@ -452,11 +453,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - name: request.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + name: request.name || '', + }); this.initialize(); return this.innerApiCalls.createTopic(request, options, callback); } @@ -543,11 +543,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'topic.name': request.topic!.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'topic.name': request.topic!.name || '', + }); this.initialize(); return this.innerApiCalls.updateTopic(request, options, callback); } @@ -631,11 +630,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); this.initialize(); return this.innerApiCalls.publish(request, options, callback); } @@ -716,11 +714,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); this.initialize(); return this.innerApiCalls.getTopic(request, options, callback); } @@ -805,11 +802,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); this.initialize(); return this.innerApiCalls.deleteTopic(request, options, callback); } @@ -893,11 +889,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.detachSubscription(request, options, callback); } @@ -988,11 +983,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); this.initialize(); return this.innerApiCalls.listTopics(request, options, callback); } @@ -1030,11 +1024,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopics.createStream( @@ -1083,17 +1076,16 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopics.asyncIterate( this.innerApiCalls['listTopics'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } @@ -1191,11 +1183,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); this.initialize(); return this.innerApiCalls.listTopicSubscriptions( request, @@ -1237,11 +1228,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopicSubscriptions.createStream( @@ -1290,17 +1280,16 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopicSubscriptions.asyncIterate( this.innerApiCalls['listTopicSubscriptions'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } @@ -1396,11 +1385,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); this.initialize(); return this.innerApiCalls.listTopicSnapshots(request, options, callback); } @@ -1438,11 +1426,10 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopicSnapshots.createStream( @@ -1491,17 +1478,16 @@ export class PublisherClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - topic: request.topic || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + topic: request.topic || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listTopicSnapshots.asyncIterate( this.innerApiCalls['listTopicSnapshots'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } diff --git a/src/v1/schema_service_client.ts b/src/v1/schema_service_client.ts index 23038577f..7810a7d07 100644 --- a/src/v1/schema_service_client.ts +++ b/src/v1/schema_service_client.ts @@ -238,13 +238,14 @@ export class SchemaServiceClient { ]; for (const methodName of schemaServiceStubMethods) { const callPromise = this.schemaServiceStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, + stub => + (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, (err: Error | null | undefined) => () => { throw err; } @@ -408,11 +409,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); this.initialize(); return this.innerApiCalls.createSchema(request, options, callback); } @@ -497,11 +497,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - name: request.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + name: request.name || '', + }); this.initialize(); return this.innerApiCalls.getSchema(request, options, callback); } @@ -582,11 +581,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - name: request.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + name: request.name || '', + }); this.initialize(); return this.innerApiCalls.deleteSchema(request, options, callback); } @@ -669,11 +667,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); this.initialize(); return this.innerApiCalls.validateSchema(request, options, callback); } @@ -764,11 +761,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); this.initialize(); return this.innerApiCalls.validateMessage(request, options, callback); } @@ -863,11 +859,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); this.initialize(); return this.innerApiCalls.listSchemas(request, options, callback); } @@ -909,11 +904,10 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSchemas.createStream( @@ -966,17 +960,16 @@ export class SchemaServiceClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - parent: request.parent || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + parent: request.parent || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSchemas.asyncIterate( this.innerApiCalls['listSchemas'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } diff --git a/src/v1/subscriber_client.ts b/src/v1/subscriber_client.ts index 258740cb7..b619413a3 100644 --- a/src/v1/subscriber_client.ts +++ b/src/v1/subscriber_client.ts @@ -263,13 +263,14 @@ export class SubscriberClient { ]; for (const methodName of subscriberStubMethods) { const callPromise = this.subscriberStub.then( - stub => (...args: Array<{}>) => { - if (this._terminated) { - return Promise.reject('The client has already been closed.'); - } - const func = stub[methodName]; - return func.apply(stub, args); - }, + stub => + (...args: Array<{}>) => { + if (this._terminated) { + return Promise.reject('The client has already been closed.'); + } + const func = stub[methodName]; + return func.apply(stub, args); + }, (err: Error | null | undefined) => () => { throw err; } @@ -524,11 +525,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - name: request.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + name: request.name || '', + }); this.initialize(); return this.innerApiCalls.createSubscription(request, options, callback); } @@ -609,11 +609,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.getSubscription(request, options, callback); } @@ -697,11 +696,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'subscription.name': request.subscription!.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'subscription.name': request.subscription!.name || '', + }); this.initialize(); return this.innerApiCalls.updateSubscription(request, options, callback); } @@ -786,11 +784,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.deleteSubscription(request, options, callback); } @@ -886,11 +883,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.modifyAckDeadline(request, options, callback); } @@ -981,11 +977,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.acknowledge(request, options, callback); } @@ -1080,11 +1075,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.pull(request, options, callback); } @@ -1177,11 +1171,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.modifyPushConfig(request, options, callback); } @@ -1266,11 +1259,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - snapshot: request.snapshot || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + snapshot: request.snapshot || '', + }); this.initialize(); return this.innerApiCalls.getSnapshot(request, options, callback); } @@ -1383,11 +1375,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - name: request.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + name: request.name || '', + }); this.initialize(); return this.innerApiCalls.createSnapshot(request, options, callback); } @@ -1475,11 +1466,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - 'snapshot.name': request.snapshot!.name || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + 'snapshot.name': request.snapshot!.name || '', + }); this.initialize(); return this.innerApiCalls.updateSnapshot(request, options, callback); } @@ -1568,11 +1558,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - snapshot: request.snapshot || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + snapshot: request.snapshot || '', + }); this.initialize(); return this.innerApiCalls.deleteSnapshot(request, options, callback); } @@ -1674,11 +1663,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - subscription: request.subscription || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + subscription: request.subscription || '', + }); this.initialize(); return this.innerApiCalls.seek(request, options, callback); } @@ -1799,11 +1787,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); this.initialize(); return this.innerApiCalls.listSubscriptions(request, options, callback); } @@ -1841,11 +1828,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSubscriptions.createStream( @@ -1894,17 +1880,16 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSubscriptions.asyncIterate( this.innerApiCalls['listSubscriptions'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } @@ -1998,11 +1983,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); this.initialize(); return this.innerApiCalls.listSnapshots(request, options, callback); } @@ -2040,11 +2024,10 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSnapshots.createStream( @@ -2093,17 +2076,16 @@ export class SubscriberClient { options = options || {}; options.otherArgs = options.otherArgs || {}; options.otherArgs.headers = options.otherArgs.headers || {}; - options.otherArgs.headers[ - 'x-goog-request-params' - ] = gax.routingHeader.fromParams({ - project: request.project || '', - }); + options.otherArgs.headers['x-goog-request-params'] = + gax.routingHeader.fromParams({ + project: request.project || '', + }); options = options || {}; const callSettings = new gax.CallSettings(options); this.initialize(); return this.descriptors.page.listSnapshots.asyncIterate( this.innerApiCalls['listSnapshots'] as GaxCall, - (request as unknown) as RequestType, + request as unknown as RequestType, callSettings ) as AsyncIterable; } diff --git a/system-test/install.ts b/system-test/install.ts index d1b9705ce..5021ce4d6 100644 --- a/system-test/install.ts +++ b/system-test/install.ts @@ -20,7 +20,7 @@ import {promisify} from 'util'; import {describe, it, after} from 'mocha'; const keep = false; -const mvp = (promisify(mv) as {}) as (...args: string[]) => Promise; +const mvp = promisify(mv) as {} as (...args: string[]) => Promise; const ncpp = promisify(ncp); const stagingDir = tmp.dirSync({keep, unsafeCleanup: true}); const stagingPath = stagingDir.name; diff --git a/test/gapic_publisher_v1.ts b/test/gapic_publisher_v1.ts index 29e25905d..b23de6e7a 100644 --- a/test/gapic_publisher_v1.ts +++ b/test/gapic_publisher_v1.ts @@ -28,10 +28,9 @@ import {PassThrough} from 'stream'; import {protobuf, IamProtos} from 'google-gax'; function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message).toObject( - instance as protobuf.Message, - {defaults: true} - ); + 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; @@ -247,9 +246,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Topic() ); - client.innerApiCalls.createTopic = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.createTopic = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.createTopic( request, @@ -361,9 +359,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Topic() ); - client.innerApiCalls.updateTopic = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.updateTopic = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.updateTopic( request, @@ -474,9 +471,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.PublishResponse() ); - client.innerApiCalls.publish = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.publish = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.publish( request, @@ -583,9 +579,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Topic() ); - client.innerApiCalls.getTopic = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.getTopic = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.getTopic( request, @@ -692,9 +687,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.deleteTopic = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.deleteTopic = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.deleteTopic( request, @@ -773,9 +767,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.DetachSubscriptionResponse() ); - client.innerApiCalls.detachSubscription = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.detachSubscription = + stubSimpleCall(expectedResponse); const [response] = await client.detachSubscription(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -806,9 +799,8 @@ describe('v1.PublisherClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.DetachSubscriptionResponse() ); - client.innerApiCalls.detachSubscription = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.detachSubscription = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.detachSubscription( request, @@ -922,9 +914,8 @@ describe('v1.PublisherClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Topic()), generateSampleMessage(new protos.google.pubsub.v1.Topic()), ]; - client.innerApiCalls.listTopics = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listTopics = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listTopics( request, @@ -996,9 +987,8 @@ describe('v1.PublisherClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Topic()), generateSampleMessage(new protos.google.pubsub.v1.Topic()), ]; - client.descriptors.page.listTopics.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listTopics.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listTopicsStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Topic[] = []; @@ -1086,9 +1076,8 @@ describe('v1.PublisherClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Topic()), generateSampleMessage(new protos.google.pubsub.v1.Topic()), ]; - client.descriptors.page.listTopics.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listTopics.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: protos.google.pubsub.v1.ITopic[] = []; const iterable = client.listTopicsAsync(request); for await (const resource of iterable) { @@ -1167,9 +1156,8 @@ describe('v1.PublisherClient', () => { }, }; const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSubscriptions = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.listTopicSubscriptions = + stubSimpleCall(expectedResponse); const [response] = await client.listTopicSubscriptions(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -1198,9 +1186,8 @@ describe('v1.PublisherClient', () => { }, }; const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSubscriptions = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listTopicSubscriptions = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listTopicSubscriptions( request, @@ -1268,9 +1255,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listTopicSubscriptions.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listTopicSubscriptionsStream(request); const promise = new Promise((resolve, reject) => { const responses: string[] = []; @@ -1287,16 +1273,18 @@ describe('v1.PublisherClient', () => { const responses = await promise; assert.deepStrictEqual(responses, expectedResponse); assert( - (client.descriptors.page.listTopicSubscriptions - .createStream as SinonStub) + ( + client.descriptors.page.listTopicSubscriptions + .createStream as SinonStub + ) .getCall(0) .calledWith(client.innerApiCalls.listTopicSubscriptions, request) ); assert.strictEqual( - (client.descriptors.page.listTopicSubscriptions - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSubscriptions + .createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1313,10 +1301,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedError = new Error('expected'); - client.descriptors.page.listTopicSubscriptions.createStream = stubPageStreamingCall( - undefined, - expectedError - ); + client.descriptors.page.listTopicSubscriptions.createStream = + stubPageStreamingCall(undefined, expectedError); const stream = client.listTopicSubscriptionsStream(request); const promise = new Promise((resolve, reject) => { const responses: string[] = []; @@ -1332,16 +1318,18 @@ describe('v1.PublisherClient', () => { }); await assert.rejects(promise, expectedError); assert( - (client.descriptors.page.listTopicSubscriptions - .createStream as SinonStub) + ( + client.descriptors.page.listTopicSubscriptions + .createStream as SinonStub + ) .getCall(0) .calledWith(client.innerApiCalls.listTopicSubscriptions, request) ); assert.strictEqual( - (client.descriptors.page.listTopicSubscriptions - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSubscriptions + .createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1358,9 +1346,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listTopicSubscriptions.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: string[] = []; const iterable = client.listTopicSubscriptionsAsync(request); for await (const resource of iterable) { @@ -1368,15 +1355,17 @@ describe('v1.PublisherClient', () => { } assert.deepStrictEqual(responses, expectedResponse); assert.deepStrictEqual( - (client.descriptors.page.listTopicSubscriptions - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listTopicSubscriptions + .asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listTopicSubscriptions - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSubscriptions + .asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1393,10 +1382,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedError = new Error('expected'); - client.descriptors.page.listTopicSubscriptions.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); + client.descriptors.page.listTopicSubscriptions.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); const iterable = client.listTopicSubscriptionsAsync(request); await assert.rejects(async () => { const responses: string[] = []; @@ -1405,15 +1392,17 @@ describe('v1.PublisherClient', () => { } }); assert.deepStrictEqual( - (client.descriptors.page.listTopicSubscriptions - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listTopicSubscriptions + .asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listTopicSubscriptions - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSubscriptions + .asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1439,9 +1428,8 @@ describe('v1.PublisherClient', () => { }, }; const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSnapshots = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.listTopicSnapshots = + stubSimpleCall(expectedResponse); const [response] = await client.listTopicSnapshots(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -1470,9 +1458,8 @@ describe('v1.PublisherClient', () => { }, }; const expectedResponse = [new String(), new String(), new String()]; - client.innerApiCalls.listTopicSnapshots = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listTopicSnapshots = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listTopicSnapshots( request, @@ -1537,9 +1524,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listTopicSnapshots.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listTopicSnapshotsStream(request); const promise = new Promise((resolve, reject) => { const responses: string[] = []; @@ -1561,10 +1547,9 @@ describe('v1.PublisherClient', () => { .calledWith(client.innerApiCalls.listTopicSnapshots, request) ); assert.strictEqual( - (client.descriptors.page.listTopicSnapshots - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSnapshots.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1581,10 +1566,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedError = new Error('expected'); - client.descriptors.page.listTopicSnapshots.createStream = stubPageStreamingCall( - undefined, - expectedError - ); + client.descriptors.page.listTopicSnapshots.createStream = + stubPageStreamingCall(undefined, expectedError); const stream = client.listTopicSnapshotsStream(request); const promise = new Promise((resolve, reject) => { const responses: string[] = []; @@ -1605,10 +1588,9 @@ describe('v1.PublisherClient', () => { .calledWith(client.innerApiCalls.listTopicSnapshots, request) ); assert.strictEqual( - (client.descriptors.page.listTopicSnapshots - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSnapshots.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1625,9 +1607,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedResponse = [new String(), new String(), new String()]; - client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listTopicSnapshots.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: string[] = []; const iterable = client.listTopicSnapshotsAsync(request); for await (const resource of iterable) { @@ -1635,15 +1616,15 @@ describe('v1.PublisherClient', () => { } assert.deepStrictEqual(responses, expectedResponse); assert.deepStrictEqual( - (client.descriptors.page.listTopicSnapshots - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listTopicSnapshots - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1660,10 +1641,8 @@ describe('v1.PublisherClient', () => { request.topic = ''; const expectedHeaderRequestParams = 'topic='; const expectedError = new Error('expected'); - client.descriptors.page.listTopicSnapshots.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); + client.descriptors.page.listTopicSnapshots.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); const iterable = client.listTopicSnapshotsAsync(request); await assert.rejects(async () => { const responses: string[] = []; @@ -1672,15 +1651,15 @@ describe('v1.PublisherClient', () => { } }); assert.deepStrictEqual( - (client.descriptors.page.listTopicSnapshots - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listTopicSnapshots - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listTopicSnapshots.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); diff --git a/test/gapic_schema_service_v1.ts b/test/gapic_schema_service_v1.ts index 9fb79f071..e91cb764e 100644 --- a/test/gapic_schema_service_v1.ts +++ b/test/gapic_schema_service_v1.ts @@ -28,10 +28,9 @@ import {PassThrough} from 'stream'; import {protobuf, IamProtos} from 'google-gax'; function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message).toObject( - instance as protobuf.Message, - {defaults: true} - ); + 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; @@ -247,9 +246,8 @@ describe('v1.SchemaServiceClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Schema() ); - client.innerApiCalls.createSchema = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.createSchema = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.createSchema( request, @@ -359,9 +357,8 @@ describe('v1.SchemaServiceClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Schema() ); - client.innerApiCalls.getSchema = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.getSchema = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.getSchema( request, @@ -468,9 +465,8 @@ describe('v1.SchemaServiceClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.deleteSchema = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.deleteSchema = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.deleteSchema( request, @@ -580,9 +576,8 @@ describe('v1.SchemaServiceClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.ValidateSchemaResponse() ); - client.innerApiCalls.validateSchema = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.validateSchema = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.validateSchema( request, @@ -692,9 +687,8 @@ describe('v1.SchemaServiceClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.ValidateMessageResponse() ); - client.innerApiCalls.validateMessage = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.validateMessage = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.validateMessage( request, @@ -808,9 +802,8 @@ describe('v1.SchemaServiceClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Schema()), generateSampleMessage(new protos.google.pubsub.v1.Schema()), ]; - client.innerApiCalls.listSchemas = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listSchemas = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listSchemas( request, @@ -882,9 +875,8 @@ describe('v1.SchemaServiceClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Schema()), generateSampleMessage(new protos.google.pubsub.v1.Schema()), ]; - client.descriptors.page.listSchemas.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listSchemas.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listSchemasStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Schema[] = []; @@ -972,9 +964,8 @@ describe('v1.SchemaServiceClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Schema()), generateSampleMessage(new protos.google.pubsub.v1.Schema()), ]; - client.descriptors.page.listSchemas.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listSchemas.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: protos.google.pubsub.v1.ISchema[] = []; const iterable = client.listSchemasAsync(request); for await (const resource of iterable) { diff --git a/test/gapic_subscriber_v1.ts b/test/gapic_subscriber_v1.ts index 1ead2c3c3..b8cbaa7f7 100644 --- a/test/gapic_subscriber_v1.ts +++ b/test/gapic_subscriber_v1.ts @@ -28,10 +28,9 @@ import {PassThrough} from 'stream'; import {protobuf, IamProtos} from 'google-gax'; function generateSampleMessage(instance: T) { - const filledObject = (instance.constructor as typeof protobuf.Message).toObject( - instance as protobuf.Message, - {defaults: true} - ); + 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; @@ -230,9 +229,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Subscription() ); - client.innerApiCalls.createSubscription = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.createSubscription = + stubSimpleCall(expectedResponse); const [response] = await client.createSubscription(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -263,9 +261,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Subscription() ); - client.innerApiCalls.createSubscription = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.createSubscription = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.createSubscription( request, @@ -375,9 +372,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Subscription() ); - client.innerApiCalls.getSubscription = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.getSubscription = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.getSubscription( request, @@ -457,9 +453,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Subscription() ); - client.innerApiCalls.updateSubscription = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.updateSubscription = + stubSimpleCall(expectedResponse); const [response] = await client.updateSubscription(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -491,9 +486,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Subscription() ); - client.innerApiCalls.updateSubscription = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.updateSubscription = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.updateSubscription( request, @@ -573,9 +567,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.deleteSubscription = stubSimpleCall( - expectedResponse - ); + client.innerApiCalls.deleteSubscription = + stubSimpleCall(expectedResponse); const [response] = await client.deleteSubscription(request); assert.deepStrictEqual(response, expectedResponse); assert( @@ -606,9 +599,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.deleteSubscription = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.deleteSubscription = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.deleteSubscription( request, @@ -718,9 +710,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.modifyAckDeadline = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.modifyAckDeadline = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.modifyAckDeadline( request, @@ -830,9 +821,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.acknowledge = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.acknowledge = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.acknowledge( request, @@ -1049,9 +1039,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.modifyPushConfig = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.modifyPushConfig = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.modifyPushConfig( request, @@ -1161,9 +1150,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Snapshot() ); - client.innerApiCalls.getSnapshot = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.getSnapshot = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.getSnapshot( request, @@ -1273,9 +1261,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Snapshot() ); - client.innerApiCalls.createSnapshot = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.createSnapshot = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.createSnapshot( request, @@ -1387,9 +1374,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.Snapshot() ); - client.innerApiCalls.updateSnapshot = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.updateSnapshot = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.updateSnapshot( request, @@ -1500,9 +1486,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.protobuf.Empty() ); - client.innerApiCalls.deleteSnapshot = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.deleteSnapshot = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.deleteSnapshot( request, @@ -1679,9 +1664,8 @@ describe('v1.SubscriberClient', () => { const expectedResponse = generateSampleMessage( new protos.google.pubsub.v1.StreamingPullResponse() ); - client.innerApiCalls.streamingPull = stubBidiStreamingCall( - expectedResponse - ); + client.innerApiCalls.streamingPull = + stubBidiStreamingCall(expectedResponse); const stream = client.streamingPull(); const promise = new Promise((resolve, reject) => { stream.on( @@ -1704,9 +1688,8 @@ describe('v1.SubscriberClient', () => { .calledWithExactly(undefined) ); assert.deepStrictEqual( - (((stream as unknown) as PassThrough)._transform as SinonStub).getCall( - 0 - ).args[0], + ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) + .args[0], request ); }); @@ -1746,9 +1729,8 @@ describe('v1.SubscriberClient', () => { .calledWithExactly(undefined) ); assert.deepStrictEqual( - (((stream as unknown) as PassThrough)._transform as SinonStub).getCall( - 0 - ).args[0], + ((stream as unknown as PassThrough)._transform as SinonStub).getCall(0) + .args[0], request ); }); @@ -1811,9 +1793,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Subscription()), generateSampleMessage(new protos.google.pubsub.v1.Subscription()), ]; - client.innerApiCalls.listSubscriptions = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listSubscriptions = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listSubscriptions( request, @@ -1885,9 +1866,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Subscription()), generateSampleMessage(new protos.google.pubsub.v1.Subscription()), ]; - client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listSubscriptions.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listSubscriptionsStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Subscription[] = []; @@ -1909,10 +1889,9 @@ describe('v1.SubscriberClient', () => { .calledWith(client.innerApiCalls.listSubscriptions, request) ); assert.strictEqual( - (client.descriptors.page.listSubscriptions - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSubscriptions.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1929,10 +1908,8 @@ describe('v1.SubscriberClient', () => { request.project = ''; const expectedHeaderRequestParams = 'project='; const expectedError = new Error('expected'); - client.descriptors.page.listSubscriptions.createStream = stubPageStreamingCall( - undefined, - expectedError - ); + client.descriptors.page.listSubscriptions.createStream = + stubPageStreamingCall(undefined, expectedError); const stream = client.listSubscriptionsStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Subscription[] = []; @@ -1953,10 +1930,9 @@ describe('v1.SubscriberClient', () => { .calledWith(client.innerApiCalls.listSubscriptions, request) ); assert.strictEqual( - (client.descriptors.page.listSubscriptions - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSubscriptions.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -1977,9 +1953,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Subscription()), generateSampleMessage(new protos.google.pubsub.v1.Subscription()), ]; - client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listSubscriptions.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: protos.google.pubsub.v1.ISubscription[] = []; const iterable = client.listSubscriptionsAsync(request); for await (const resource of iterable) { @@ -1987,15 +1962,15 @@ describe('v1.SubscriberClient', () => { } assert.deepStrictEqual(responses, expectedResponse); assert.deepStrictEqual( - (client.descriptors.page.listSubscriptions - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listSubscriptions.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listSubscriptions - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSubscriptions.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -2012,10 +1987,8 @@ describe('v1.SubscriberClient', () => { request.project = ''; const expectedHeaderRequestParams = 'project='; const expectedError = new Error('expected'); - client.descriptors.page.listSubscriptions.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); + client.descriptors.page.listSubscriptions.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); const iterable = client.listSubscriptionsAsync(request); await assert.rejects(async () => { const responses: protos.google.pubsub.v1.ISubscription[] = []; @@ -2024,15 +1997,15 @@ describe('v1.SubscriberClient', () => { } }); assert.deepStrictEqual( - (client.descriptors.page.listSubscriptions - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listSubscriptions.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listSubscriptions - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSubscriptions.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -2095,9 +2068,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), ]; - client.innerApiCalls.listSnapshots = stubSimpleCallWithCallback( - expectedResponse - ); + client.innerApiCalls.listSnapshots = + stubSimpleCallWithCallback(expectedResponse); const promise = new Promise((resolve, reject) => { client.listSnapshots( request, @@ -2169,9 +2141,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), ]; - client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall( - expectedResponse - ); + client.descriptors.page.listSnapshots.createStream = + stubPageStreamingCall(expectedResponse); const stream = client.listSnapshotsStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Snapshot[] = []; @@ -2193,10 +2164,9 @@ describe('v1.SubscriberClient', () => { .calledWith(client.innerApiCalls.listSnapshots, request) ); assert.strictEqual( - (client.descriptors.page.listSnapshots - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSnapshots.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -2213,10 +2183,8 @@ describe('v1.SubscriberClient', () => { request.project = ''; const expectedHeaderRequestParams = 'project='; const expectedError = new Error('expected'); - client.descriptors.page.listSnapshots.createStream = stubPageStreamingCall( - undefined, - expectedError - ); + client.descriptors.page.listSnapshots.createStream = + stubPageStreamingCall(undefined, expectedError); const stream = client.listSnapshotsStream(request); const promise = new Promise((resolve, reject) => { const responses: protos.google.pubsub.v1.Snapshot[] = []; @@ -2237,10 +2205,9 @@ describe('v1.SubscriberClient', () => { .calledWith(client.innerApiCalls.listSnapshots, request) ); assert.strictEqual( - (client.descriptors.page.listSnapshots - .createStream as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSnapshots.createStream as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -2261,9 +2228,8 @@ describe('v1.SubscriberClient', () => { generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), generateSampleMessage(new protos.google.pubsub.v1.Snapshot()), ]; - client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall( - expectedResponse - ); + client.descriptors.page.listSnapshots.asyncIterate = + stubAsyncIterationCall(expectedResponse); const responses: protos.google.pubsub.v1.ISnapshot[] = []; const iterable = client.listSnapshotsAsync(request); for await (const resource of iterable) { @@ -2271,15 +2237,15 @@ describe('v1.SubscriberClient', () => { } assert.deepStrictEqual(responses, expectedResponse); assert.deepStrictEqual( - (client.descriptors.page.listSnapshots - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listSnapshots.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listSnapshots - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSnapshots.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); @@ -2296,10 +2262,8 @@ describe('v1.SubscriberClient', () => { request.project = ''; const expectedHeaderRequestParams = 'project='; const expectedError = new Error('expected'); - client.descriptors.page.listSnapshots.asyncIterate = stubAsyncIterationCall( - undefined, - expectedError - ); + client.descriptors.page.listSnapshots.asyncIterate = + stubAsyncIterationCall(undefined, expectedError); const iterable = client.listSnapshotsAsync(request); await assert.rejects(async () => { const responses: protos.google.pubsub.v1.ISnapshot[] = []; @@ -2308,15 +2272,15 @@ describe('v1.SubscriberClient', () => { } }); assert.deepStrictEqual( - (client.descriptors.page.listSnapshots - .asyncIterate as SinonStub).getCall(0).args[1], + ( + client.descriptors.page.listSnapshots.asyncIterate as SinonStub + ).getCall(0).args[1], request ); assert.strictEqual( - (client.descriptors.page.listSnapshots - .asyncIterate as SinonStub).getCall(0).args[2].otherArgs.headers[ - 'x-goog-request-params' - ], + ( + client.descriptors.page.listSnapshots.asyncIterate as SinonStub + ).getCall(0).args[2].otherArgs.headers['x-goog-request-params'], expectedHeaderRequestParams ); }); diff --git a/test/iam.ts b/test/iam.ts index b916313f1..6adaa5e91 100644 --- a/test/iam.ts +++ b/test/iam.ts @@ -35,10 +35,10 @@ describe('IAM', () => { let IAM: typeof iamTypes.IAM; let iam: iamTypes.IAM; - const PUBSUB = ({ + const PUBSUB = { options: {}, request: util.noop, - } as {}) as PubSub; + } as {} as PubSub; const ID = 'id'; before(() => { @@ -58,14 +58,14 @@ describe('IAM', () => { it('should localize pubsub#request', () => { const fakeRequest = () => {}; - const fakePubsub = ({ + const fakePubsub = { request: { bind(context: PubSub) { assert.strictEqual(context, fakePubsub); return fakeRequest; }, }, - } as {}) as PubSub; + } as {} as PubSub; const iam = new IAM(fakePubsub, ID); assert.strictEqual(iam.request, fakeRequest); diff --git a/test/lease-manager.ts b/test/lease-manager.ts index 93d210595..d8e4bee86 100644 --- a/test/lease-manager.ts +++ b/test/lease-manager.ts @@ -62,7 +62,7 @@ describe('LeaseManager', () => { }); beforeEach(() => { - subscriber = (new FakeSubscriber() as {}) as Subscriber; + subscriber = new FakeSubscriber() as {} as Subscriber; leaseManager = new LeaseManager(subscriber); }); @@ -89,8 +89,8 @@ describe('LeaseManager', () => { it('should return the number of pending messages', () => { leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); - leaseManager.add((new FakeMessage() as {}) as Message); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); + leaseManager.add(new FakeMessage() as {} as Message); assert.strictEqual(leaseManager.pending, 1); }); @@ -98,8 +98,8 @@ describe('LeaseManager', () => { describe('size', () => { it('should return the number of messages', () => { - leaseManager.add((new FakeMessage() as {}) as Message); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); + leaseManager.add(new FakeMessage() as {} as Message); assert.strictEqual(leaseManager.size, 2); }); @@ -107,7 +107,7 @@ describe('LeaseManager', () => { describe('add', () => { it('should update the bytes/size values', () => { - const message = (new FakeMessage() as {}) as Message; + const message = new FakeMessage() as {} as Message; leaseManager.add(message); @@ -116,7 +116,7 @@ describe('LeaseManager', () => { }); it('should dispatch the message if allowExcessMessages is true', done => { - const fakeMessage = (new FakeMessage() as {}) as Message; + const fakeMessage = new FakeMessage() as {} as Message; leaseManager.isFull = () => true; leaseManager.setOptions({allowExcessMessages: true}); @@ -130,7 +130,7 @@ describe('LeaseManager', () => { }); it('should dispatch the message if the inventory is not full', done => { - const fakeMessage = (new FakeMessage() as {}) as Message; + const fakeMessage = new FakeMessage() as {} as Message; leaseManager.isFull = () => false; leaseManager.setOptions({allowExcessMessages: false}); @@ -144,7 +144,7 @@ describe('LeaseManager', () => { }); it('should not dispatch the message if the inventory is full', done => { - const fakeMessage = (new FakeMessage() as {}) as Message; + const fakeMessage = new FakeMessage() as {} as Message; leaseManager.isFull = () => true; leaseManager.setOptions({allowExcessMessages: false}); @@ -158,7 +158,7 @@ describe('LeaseManager', () => { }); it('should not dispatch the message if the sub closes', done => { - const fakeMessage = (new FakeMessage() as {}) as Message; + const fakeMessage = new FakeMessage() as {} as Message; leaseManager.isFull = () => false; @@ -175,7 +175,7 @@ describe('LeaseManager', () => { leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); leaseManager.on('full', done); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); }); describe('extending deadlines', () => { @@ -196,7 +196,7 @@ describe('LeaseManager', () => { }); it('should schedule a lease extension', () => { - const message = (new FakeMessage() as {}) as Message; + const message = new FakeMessage() as {} as Message; const stub = sandbox .stub(message, 'modAck') .withArgs(subscriber.ackDeadline); @@ -214,12 +214,12 @@ describe('LeaseManager', () => { // since only 1 timeout should be set, even if add messages at different // times, they should all get extended at the same time messages.forEach(message => { - leaseManager.add((message as {}) as Message); + leaseManager.add(message as {} as Message); clock.tick(halfway); }); messages.forEach((fakeMessage, i) => { - const [deadline] = (stubs[i].lastCall.args as {}) as [number]; + const [deadline] = stubs[i].lastCall.args as {} as [number]; assert.strictEqual(deadline, subscriber.ackDeadline); }); }); @@ -230,7 +230,7 @@ describe('LeaseManager', () => { leaseManager.setOptions({maxExtension}); badMessages.forEach(message => - leaseManager.add((message as {}) as Message) + leaseManager.add(message as {} as Message) ); clock.tick(halfway); @@ -239,7 +239,7 @@ describe('LeaseManager', () => { const removeStub = sandbox.stub(leaseManager, 'remove'); const modAckStub = sandbox.stub(goodMessage, 'modAck'); - leaseManager.add((goodMessage as {}) as Message); + leaseManager.add(goodMessage as {} as Message); clock.tick(halfway); // make sure the expired messages were forgotten @@ -250,7 +250,7 @@ describe('LeaseManager', () => { assert.strictEqual(message, fakeMessage); }); - const [deadline] = (modAckStub.lastCall.args as {}) as [number]; + const [deadline] = modAckStub.lastCall.args as {} as [number]; assert.strictEqual(deadline, subscriber.ackDeadline); }); @@ -261,7 +261,7 @@ describe('LeaseManager', () => { .stub(message, 'modAck') .withArgs(subscriber.ackDeadline); - leaseManager.add((message as {}) as Message); + leaseManager.add(message as {} as Message); clock.tick(expectedTimeout); assert.strictEqual(stub.callCount, 1); @@ -273,8 +273,8 @@ describe('LeaseManager', () => { describe('clear', () => { it('should completely clear out the inventory', () => { - leaseManager.add((new FakeMessage() as {}) as Message); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); + leaseManager.add(new FakeMessage() as {} as Message); leaseManager.clear(); assert.strictEqual(leaseManager.bytes, 0); @@ -283,7 +283,7 @@ describe('LeaseManager', () => { it('should emit the free event if it was full', done => { leaseManager.setOptions({maxMessages: 1}); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); leaseManager.on('free', done); setImmediate(() => leaseManager.clear()); @@ -293,7 +293,7 @@ describe('LeaseManager', () => { const clock = sandbox.useFakeTimers(); const stub = sandbox.stub(subscriber, 'modAck').resolves(); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); leaseManager.clear(); // this would otherwise trigger a minimum of 2 modAcks @@ -308,8 +308,8 @@ describe('LeaseManager', () => { const maxMessages = 1; leaseManager.setOptions({maxMessages}); - leaseManager.add((new FakeMessage() as {}) as Message); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); + leaseManager.add(new FakeMessage() as {} as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -319,7 +319,7 @@ describe('LeaseManager', () => { const maxBytes = message.length - 1; leaseManager.setOptions({maxBytes}); - leaseManager.add((message as {}) as Message); + leaseManager.add(message as {} as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -330,7 +330,7 @@ describe('LeaseManager', () => { const maxBytes = message.length + 1; leaseManager.setOptions({maxMessages, maxBytes}); - leaseManager.add((message as {}) as Message); + leaseManager.add(message as {} as Message); assert.strictEqual(leaseManager.isFull(), false); }); @@ -340,15 +340,15 @@ describe('LeaseManager', () => { it('should noop for unknown messages', () => { const message = new FakeMessage(); - leaseManager.add((message as {}) as Message); - leaseManager.remove((new FakeMessage() as {}) as Message); + leaseManager.add(message as {} as Message); + leaseManager.remove(new FakeMessage() as {} as Message); assert.strictEqual(leaseManager.size, 1); assert.strictEqual(leaseManager.bytes, message.length); }); it('should update the bytes/size values', () => { - const message = (new FakeMessage() as {}) as Message; + const message = new FakeMessage() as {} as Message; leaseManager.add(message); leaseManager.remove(message); @@ -358,7 +358,7 @@ describe('LeaseManager', () => { }); it('should emit the free event if there is free space', done => { - const message = (new FakeMessage() as {}) as Message; + const message = new FakeMessage() as {} as Message; leaseManager.setOptions({maxMessages: 1}); leaseManager.add(message); @@ -371,7 +371,7 @@ describe('LeaseManager', () => { }); it('should remove a message from the pending state', done => { - const pending = (new FakeMessage() as {}) as Message; + const pending = new FakeMessage() as {} as Message; leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); @@ -381,7 +381,7 @@ describe('LeaseManager', () => { } }); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); leaseManager.add(pending); leaseManager.remove(pending); @@ -390,8 +390,8 @@ describe('LeaseManager', () => { }); it('should dispense a pending messages', done => { - const temp = (new FakeMessage() as {}) as Message; - const pending = (new FakeMessage() as {}) as Message; + const temp = new FakeMessage() as {} as Message; + const pending = new FakeMessage() as {} as Message; leaseManager.setOptions({allowExcessMessages: false, maxMessages: 1}); @@ -412,7 +412,7 @@ describe('LeaseManager', () => { it('should cancel any extensions if no messages are left', () => { const clock = sandbox.useFakeTimers(); - const message = (new FakeMessage() as {}) as Message; + const message = new FakeMessage() as {} as Message; const stub = sandbox.stub(subscriber, 'modAck').resolves(); leaseManager.add(message); @@ -428,7 +428,7 @@ describe('LeaseManager', () => { it('should allow excess messages by default', () => {}); it('should default maxBytes', () => { - const littleMessage = (new FakeMessage() as {}) as Message; + const littleMessage = new FakeMessage() as {} as Message; const bigMessage = new FakeMessage(); leaseManager.add(littleMessage); @@ -436,7 +436,7 @@ describe('LeaseManager', () => { leaseManager.remove(littleMessage); bigMessage.length = defaultOptions.subscription.maxOutstandingBytes * 2; - leaseManager.add((bigMessage as {}) as Message); + leaseManager.add(bigMessage as {} as Message); assert.strictEqual(leaseManager.isFull(), true); }); @@ -447,7 +447,7 @@ describe('LeaseManager', () => { i++ ) { assert.strictEqual(leaseManager.isFull(), false); - leaseManager.add((new FakeMessage() as {}) as Message); + leaseManager.add(new FakeMessage() as {} as Message); } assert.strictEqual(leaseManager.isFull(), true); diff --git a/test/message-queues.ts b/test/message-queues.ts index 4f264674f..43bf46fdc 100644 --- a/test/message-queues.ts +++ b/test/message-queues.ts @@ -328,7 +328,7 @@ describe('MessageQueues', () => { let ackQueue: messageTypes.AckQueue; beforeEach(() => { - ackQueue = new AckQueue((subscriber as {}) as Subscriber); + ackQueue = new AckQueue(subscriber as {} as Subscriber); }); it('should send batches via Client#acknowledge', async () => { @@ -397,7 +397,7 @@ describe('MessageQueues', () => { let modAckQueue: messageTypes.ModAckQueue; beforeEach(() => { - modAckQueue = new ModAckQueue((subscriber as {}) as Subscriber); + modAckQueue = new ModAckQueue(subscriber as {} as Subscriber); }); it('should send batches via Client#modifyAckDeadline', async () => { diff --git a/test/message-stream.ts b/test/message-stream.ts index 4c5fa1719..e888bf12d 100644 --- a/test/message-stream.ts +++ b/test/message-stream.ts @@ -180,7 +180,7 @@ describe('MessageStream', () => { const gaxClient = new FakeGaxClient(); client = gaxClient.client; // we hit the grpc client directly - subscriber = (new FakeSubscriber(gaxClient) as {}) as Subscriber; + subscriber = new FakeSubscriber(gaxClient) as {} as Subscriber; messageStream = new MessageStream(subscriber); }); @@ -196,7 +196,7 @@ describe('MessageStream', () => { highWaterMark: 0, }; assert.deepStrictEqual( - ((messageStream as {}) as FakePassThrough).options, + (messageStream as {} as FakePassThrough).options, expectedOptions ); }); @@ -211,7 +211,7 @@ describe('MessageStream', () => { }; assert.deepStrictEqual( - ((ms as {}) as FakePassThrough).options, + (ms as {} as FakePassThrough).options, expectedOptions ); }); diff --git a/test/publisher/index.ts b/test/publisher/index.ts index 463b0a7d7..af9e79a40 100644 --- a/test/publisher/index.ts +++ b/test/publisher/index.ts @@ -273,7 +273,7 @@ describe('Publisher', () => { queue = new FakeOrderedQueue(publisher, orderingKey); publisher.orderedQueues.set( orderingKey, - (queue as unknown) as q.OrderedQueue + queue as unknown as q.OrderedQueue ); }); @@ -281,9 +281,9 @@ describe('Publisher', () => { publisher.orderedQueues.clear(); publisher.publishMessage(fakeMessage, spy); - queue = (publisher.orderedQueues.get( + queue = publisher.orderedQueues.get( orderingKey - ) as unknown) as FakeOrderedQueue; + ) as unknown as FakeOrderedQueue; assert(queue instanceof FakeOrderedQueue); assert.strictEqual(queue.publisher, publisher); @@ -316,9 +316,9 @@ describe('Publisher', () => { publisher.orderedQueues.clear(); publisher.publishMessage(fakeMessage, spy); - queue = (publisher.orderedQueues.get( + queue = publisher.orderedQueues.get( orderingKey - ) as unknown) as FakeOrderedQueue; + ) as unknown as FakeOrderedQueue; queue.emit('drain'); assert.strictEqual(publisher.orderedQueues.size, 0); @@ -335,9 +335,9 @@ describe('Publisher', () => { sandbox .stub(FakeOrderedQueue.prototype, '_publish') .callsFake((messages, callbacks, callback) => { - const queue = (publisher.orderedQueues.get( + const queue = publisher.orderedQueues.get( orderingKey - ) as unknown) as FakeOrderedQueue; + ) as unknown as FakeOrderedQueue; queue.emit('drain'); if (typeof callback === 'function') callback(null); }); @@ -376,7 +376,7 @@ describe('Publisher', () => { publisher.orderedQueues.set( orderingKey, - (queue as unknown) as q.OrderedQueue + queue as unknown as q.OrderedQueue ); publisher.resumePublishing(orderingKey); diff --git a/test/publisher/message-queues.ts b/test/publisher/message-queues.ts index 9db5a4b6c..9cefee6a8 100644 --- a/test/publisher/message-queues.ts +++ b/test/publisher/message-queues.ts @@ -286,7 +286,7 @@ describe('Message Queues', () => { const maxMilliseconds = 1234; queue.batchOptions = {maxMilliseconds}; - queue.pending = (1234 as unknown) as NodeJS.Timer; + queue.pending = 1234 as unknown as NodeJS.Timer; queue.add(fakeMessage, spy); clock.tick(maxMilliseconds); @@ -308,7 +308,7 @@ describe('Message Queues', () => { it('should cancel any pending publish calls', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any - const fakeHandle = (1234 as unknown) as any; + const fakeHandle = 1234 as unknown as any; const stub = sandbox.stub(global, 'clearTimeout').withArgs(fakeHandle); queue.pending = fakeHandle; @@ -488,7 +488,7 @@ describe('Message Queues', () => { it('should noop after adding if a publish is already pending', () => { const stub = sandbox.stub(queue, 'beginNextPublish'); - queue.pending = (1234 as unknown) as NodeJS.Timer; + queue.pending = 1234 as unknown as NodeJS.Timer; queue.add(fakeMessage, spy); assert.strictEqual(stub.callCount, 0); @@ -585,7 +585,7 @@ describe('Message Queues', () => { }); it('should cancel any pending publishes', () => { - const fakeHandle = (1234 as unknown) as NodeJS.Timer; + const fakeHandle = 1234 as unknown as NodeJS.Timer; const stub = sandbox.stub(global, 'clearTimeout'); queue.pending = fakeHandle; diff --git a/test/pubsub.ts b/test/pubsub.ts index 523ca79f0..282745a09 100644 --- a/test/pubsub.ts +++ b/test/pubsub.ts @@ -299,9 +299,9 @@ describe('PubSub', () => { describe('createSubscription', () => { const TOPIC_NAME = 'topic'; pubsub = new pubsubTypes.PubSub({}); - const TOPIC = (Object.assign(new FakeTopic(), { + const TOPIC = Object.assign(new FakeTopic(), { name: 'projects/' + PROJECT_ID + '/topics/' + TOPIC_NAME, - }) as {}) as Topic; + }) as {} as Topic; const SUB_NAME = 'subscription'; const SUBSCRIPTION = { @@ -800,7 +800,7 @@ describe('PubSub', () => { }; setHost('localhost'); - pubsub.options.grpc = (fakeGrpc as unknown) as typeof gax.grpc; + pubsub.options.grpc = fakeGrpc as unknown as typeof gax.grpc; pubsub.determineBaseUrl_(); assert.strictEqual(pubsub.options.sslCreds, fakeCredentials); }); @@ -869,14 +869,14 @@ describe('PubSub', () => { }); it('should build the right request', done => { - const options = ({ + const options = { a: 'b', c: 'd', gaxOpts: { e: 'f', }, autoPaginate: false, - } as {}) as pubsubTypes.PageOptions; + } as {} as pubsubTypes.PageOptions; const expectedOptions = Object.assign({}, options, { project: 'projects/' + pubsub.projectId, @@ -961,12 +961,12 @@ describe('PubSub', () => { }); it('should pass the correct arguments to the API', done => { - const options = ({ + const options = { gaxOpts: { a: 'b', }, autoPaginate: false, - } as {}) as pubsubTypes.GetSubscriptionsOptions; + } as {} as pubsubTypes.GetSubscriptionsOptions; const expectedGaxOpts = Object.assign( { @@ -1046,9 +1046,9 @@ describe('PubSub', () => { it('should call topic.getSubscriptions', done => { const topic = new FakeTopic(); - const opts = ({ + const opts = { topic, - } as {}) as pubsubTypes.GetSubscriptionsOptions; + } as {} as pubsubTypes.GetSubscriptionsOptions; topic.getSubscriptions = (options: pubsubTypes.PageOptions) => { assert.strictEqual(options, opts); @@ -1059,9 +1059,9 @@ describe('PubSub', () => { }); it('should create a topic instance from a name', done => { - const opts = ({ + const opts = { topic: TOPIC_NAME, - } as {}) as pubsubTypes.GetSubscriptionsOptions; + } as {} as pubsubTypes.GetSubscriptionsOptions; const fakeTopic = { getSubscriptions(options: pubsubTypes.PageOptions) { @@ -1099,14 +1099,14 @@ describe('PubSub', () => { }); it('should build the right request', done => { - const options = ({ + const options = { a: 'b', c: 'd', gaxOpts: { e: 'f', }, autoPaginate: false, - } as {}) as pubsubTypes.PageOptions; + } as {} as pubsubTypes.PageOptions; const expectedOptions = Object.assign({}, options, { project: 'projects/' + pubsub.projectId, @@ -1262,9 +1262,9 @@ describe('PubSub', () => { const FAKE_CLIENT_INSTANCE = class { close() {} }; - const CONFIG = ({ + const CONFIG = { client: 'FakeClient', - } as {}) as pubsubTypes.GetClientConfig; + } as {} as pubsubTypes.GetClientConfig; beforeEach(() => { sandbox.stub(pubsub, 'auth').value({getProjectId: () => util.noop}); @@ -1375,10 +1375,10 @@ describe('PubSub', () => { }); describe('getClient_', () => { - const FAKE_CLIENT_INSTANCE = ({} as unknown) as gax.ClientStub; - const CONFIG = ({ + const FAKE_CLIENT_INSTANCE = {} as unknown as gax.ClientStub; + const CONFIG = { client: 'FakeClient', - } as {}) as pubsubTypes.GetClientConfig; + } as {} as pubsubTypes.GetClientConfig; it('should get the client', done => { sandbox @@ -1461,12 +1461,12 @@ describe('PubSub', () => { }); it('should call the client method correctly', done => { - const CONFIG = ({ + const CONFIG = { client: 'FakeClient', method: 'fakeMethod', reqOpts: {a: 'a'}, gaxOpts: {}, - } as {}) as pubsubTypes.RequestConfig; + } as {} as pubsubTypes.RequestConfig; const replacedReqOpts = {}; @@ -1502,7 +1502,7 @@ describe('PubSub', () => { it('should return a Snapshot object', () => { const SNAPSHOT_NAME = 'new-snapshot'; const snapshot = pubsub.snapshot(SNAPSHOT_NAME); - const args = ((snapshot as {}) as FakeSnapshot).calledWith_; + const args = (snapshot as {} as FakeSnapshot).calledWith_; assert(snapshot instanceof FakeSnapshot); assert.strictEqual(args[0], pubsub); @@ -1571,7 +1571,7 @@ describe('PubSub', () => { const fakeOptions = {}; const topic = pubsub.topic(fakeName, fakeOptions); - const [ps, name, options] = ((topic as {}) as FakeTopic).calledWith_; + const [ps, name, options] = (topic as {} as FakeTopic).calledWith_; assert.strictEqual(ps, pubsub); assert.strictEqual(name, fakeName); diff --git a/test/snapshot.ts b/test/snapshot.ts index 4a2171bc0..5f06dcfbb 100644 --- a/test/snapshot.ts +++ b/test/snapshot.ts @@ -41,17 +41,17 @@ describe('Snapshot', () => { const SNAPSHOT_NAME = 'a'; const PROJECT_ID = 'grape-spaceship-123'; - const PUBSUB = ({ + const PUBSUB = { projectId: PROJECT_ID, - } as {}) as PubSub; + } as {} as PubSub; - const SUBSCRIPTION = ({ + const SUBSCRIPTION = { projectId: PROJECT_ID, pubsub: PUBSUB, api: {}, createSnapshot() {}, seek() {}, - } as {}) as Subscription; + } as {} as Subscription; before(() => { Snapshot = proxyquire('../src/snapshot', { diff --git a/test/subscriber.ts b/test/subscriber.ts index 031934e03..ffc900c19 100644 --- a/test/subscriber.ts +++ b/test/subscriber.ts @@ -184,7 +184,7 @@ describe('Subscriber', () => { Subscriber = s.Subscriber; // Create standard instance - subscription = (new FakeSubscription() as {}) as Subscription; + subscription = new FakeSubscription() as {} as Subscription; subscriber = new Subscriber(subscription); message = new Message(subscriber, RECEIVED_MESSAGE); subscriber.open(); @@ -438,7 +438,7 @@ describe('Subscriber', () => { describe('getClient', () => { it('should get a subscriber client', async () => { - const pubsub = (subscription.pubsub as {}) as FakePubSub; + const pubsub = subscription.pubsub as {} as FakePubSub; const spy = sandbox.spy(pubsub, 'getClient_'); const client = await subscriber.getClient(); const [options] = spy.lastCall.args; @@ -680,7 +680,7 @@ describe('Subscriber', () => { }); it('exports a span once it is created', () => { - subscription = (new FakeSubscription() as {}) as Subscription; + subscription = new FakeSubscription() as {} as Subscription; subscriber = new Subscriber(subscription, enableTracing); message = new Message(subscriber, RECEIVED_MESSAGE); assert.strictEqual(subscriber['_useOpentelemetry'], true); @@ -696,9 +696,8 @@ describe('Subscriber', () => { ackId: uuid.v4(), message: { attributes: { - googclient_OpenTelemetrySpanContext: JSON.stringify( - parentSpanContext - ), + googclient_OpenTelemetrySpanContext: + JSON.stringify(parentSpanContext), }, data: Buffer.from('Hello, world!'), messageId: uuid.v4(), @@ -798,7 +797,7 @@ describe('Subscriber', () => { it('should localize publishTime', () => { const m = new Message(subscriber, RECEIVED_MESSAGE); - const timestamp = (m.publishTime as unknown) as FakePreciseDate; + const timestamp = m.publishTime as unknown as FakePreciseDate; assert(timestamp instanceof FakePreciseDate); assert.strictEqual( diff --git a/test/subscription.ts b/test/subscription.ts index 06b49ca0c..601679e32 100644 --- a/test/subscription.ts +++ b/test/subscription.ts @@ -87,11 +87,11 @@ describe('Subscription', () => { const SUB_NAME = 'test-subscription'; const SUB_FULL_NAME = 'projects/' + PROJECT_ID + '/subscriptions/' + SUB_NAME; - const PUBSUB = ({ + const PUBSUB = { projectId: PROJECT_ID, request: util.noop, createSubscription: util.noop, - } as {}) as PubSub; + } as {} as PubSub; before(() => { Subscription = proxyquire('../src/subscription.js', { @@ -152,7 +152,7 @@ describe('Subscription', () => { it('should create an IAM object', () => { assert(subscription.iam instanceof FakeIAM); - const args = ((subscription.iam as {}) as FakeIAM).calledWith_; + const args = (subscription.iam as {} as FakeIAM).calledWith_; assert.strictEqual(args[0], PUBSUB); assert.strictEqual(args[1], subscription.name); }); @@ -339,7 +339,8 @@ describe('Subscription', () => { }); it('should throw an error if theres no topic', () => { - const expectedError = /Subscriptions can only be created when accessed through Topics/; + const expectedError = + /Subscriptions can only be created when accessed through Topics/; delete subscription.topic; assert.throws(() => subscription.create(), expectedError); });