import * as protos from '../protos/protos' ; import * as assert from 'assert' ; import * as sinon from 'sinon' ; import { SinonStub } from 'sinon' ; import { describe , it } from 'mocha' ; import * as cloudtasksModule from '../src' ; import { PassThrough } from 'stream' ; import { protobuf } from 'google-gax' ; function generateSampleMessage < T extends object > ( instance ) { const filledObject = ( instance . constructor as typeof protobuf . Message ) . toObject ( instance as protobuf . Message < T > , { defaults : true } ) ; return ( instance . constructor as typeof protobuf . Message ) . fromObject ( filledObject ) as T ; } function stubSimpleCall < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . rejects ( error ) : sinon . stub ( ) . resolves ( [ response ] ) ; } function stubSimpleCallWithCallback < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : sinon . stub ( ) . callsArgWith ( 2 , null , response ) ; } function stubPageStreamingCall < ResponseType > ( responses ? , error ? ) { const pagingStub = sinon . stub ( ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { pagingStub . onCall ( i ) . callsArgWith ( 2 , null , responses [ i ] ) ; } } const transformStub = error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : pagingStub ; const mockStream = new PassThrough ( { objectMode : true , transform : transformStub , } ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; } setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } else { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } return sinon . stub ( ) . returns ( mockStream ) ; } function stubAsyncIterationCall < ResponseType > ( responses ? , error ? ) { let counter = 0 ; const asyncIterable = { [ Symbol . asyncIterator ] ( ) { return { async next ( ) { if ( error ) { return Promise . reject ( error ) ; } if ( counter >= responses ! . length ) { return Promise . resolve ( { done : true , value : undefined } ) ; } return Promise . resolve ( { done : false , value : responses ! [ counter ++ ] } ) ; } , } ; } , } ; return sinon . stub ( ) . returns ( asyncIterable ) ; } describe ( 'v2.CloudTasksClient' , ( ) => { it ( 'has servicePath' , ( ) => { const servicePath = cloudtasksModule . v2 . CloudTasksClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = cloudtasksModule . v2 . CloudTasksClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = cloudtasksModule . v2 . CloudTasksClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; assert . strictEqual ( client . cloudTasksStub , undefined ) ; await client . initialize ( ) ; assert ( client . cloudTasksStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . resolves ( fakeProjectId ) ; const result = await client . getProjectId ( ) ; assert . strictEqual ( result , fakeProjectId ) ; assert ( ( client . auth . getProjectId as SinonStub ) . calledWithExactly ( ) ) ; } ) ; it ( 'has getProjectId method with callback' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . callsArgWith ( 0 , null , fakeProjectId ) ; const promise = new Promise ( ( resolve , reject ) => { client . getProjectId ( ( err ? , projectId ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( projectId ) ; } } ) ; } ) ; const result = await promise ; assert . strictEqual ( result , fakeProjectId ) ; } ) ; describe ( 'getQueue' , ( ) => { it ( 'invokes getQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . getQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . getQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'createQueue' , ( ) => { it ( 'invokes createQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateQueueRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . createQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateQueueRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . createQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateQueueRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updateQueue' , ( ) => { it ( 'invokes updateQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . UpdateQueueRequest ( ) ) ; request . queue = { } ; request . queue . name = '' ; const expectedHeaderRequestParams = 'queue.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . updateQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updateQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updateQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . UpdateQueueRequest ( ) ) ; request . queue = { } ; request . queue . name = '' ; const expectedHeaderRequestParams = 'queue.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . updateQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updateQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updateQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . UpdateQueueRequest ( ) ) ; request . queue = { } ; request . queue . name = '' ; const expectedHeaderRequestParams = 'queue.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updateQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updateQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updateQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteQueue' , ( ) => { it ( 'invokes deleteQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'purgeQueue' , ( ) => { it ( 'invokes purgeQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PurgeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . purgeQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . purgeQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . purgeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes purgeQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PurgeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . purgeQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . purgeQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . purgeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes purgeQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PurgeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . purgeQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . purgeQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . purgeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'pauseQueue' , ( ) => { it ( 'invokes pauseQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PauseQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . pauseQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . pauseQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . pauseQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes pauseQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PauseQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . pauseQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . pauseQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . pauseQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes pauseQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . PauseQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . pauseQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . pauseQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . pauseQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'resumeQueue' , ( ) => { it ( 'invokes resumeQueue without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ResumeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . resumeQueue = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . resumeQueue ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . resumeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes resumeQueue without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ResumeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) ; client . innerApiCalls . resumeQueue = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . resumeQueue ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . resumeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes resumeQueue with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ResumeQueueRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . resumeQueue = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . resumeQueue ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . resumeQueue as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getIamPolicy' , ( ) => { it ( 'invokes getIamPolicy without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getIamPolicy without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getIamPolicy with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'setIamPolicy' , ( ) => { it ( 'invokes setIamPolicy without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setIamPolicy without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setIamPolicy with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'testIamPermissions' , ( ) => { it ( 'invokes testIamPermissions without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . testIamPermissions ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes testIamPermissions without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . testIamPermissions ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes testIamPermissions with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . testIamPermissions ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getTask' , ( ) => { it ( 'invokes getTask without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . getTask = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getTask ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getTask without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . getTask = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getTask ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getTask with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . GetTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getTask = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getTask ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'createTask' , ( ) => { it ( 'invokes createTask without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateTaskRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . createTask = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createTask ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createTask without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateTaskRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . createTask = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createTask ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createTask with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . CreateTaskRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createTask = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createTask ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteTask' , ( ) => { it ( 'invokes deleteTask without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteTask = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteTask ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteTask without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteTask = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteTask ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteTask with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . DeleteTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteTask = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteTask ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'runTask' , ( ) => { it ( 'invokes runTask without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . RunTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . runTask = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . runTask ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . runTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes runTask without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . RunTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) ; client . innerApiCalls . runTask = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . runTask ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . runTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes runTask with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . RunTaskRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . runTask = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . runTask ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . runTask as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'listQueues' , ( ) => { it ( 'invokes listQueues without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , ] ; client . innerApiCalls . listQueues = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listQueues ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listQueues as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listQueues without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , ] ; client . innerApiCalls . listQueues = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listQueues ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listQueues as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listQueues with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listQueues = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listQueues ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listQueues as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listQueuesStream without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , ] ; client . descriptors . page . listQueues . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listQueuesStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; const responses = await promise ; assert . deepStrictEqual ( responses , expectedResponse ) ; assert ( ( client . descriptors . page . listQueues . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listQueues , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listQueues . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listQueuesStream with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listQueues . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listQueuesStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; await assert . rejects ( promise , expectedError ) ; assert ( ( client . descriptors . page . listQueues . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listQueues , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listQueues . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listQueues without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Queue ( ) ) , ] ; client . descriptors . page . listQueues . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listQueuesAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listQueues . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listQueues . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listQueues with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListQueuesRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listQueues . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listQueuesAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listQueues . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listQueues . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listTasks' , ( ) => { it ( 'invokes listTasks without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , ] ; client . innerApiCalls . listTasks = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listTasks ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listTasks as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listTasks without error using callback' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , ] ; client . innerApiCalls . listTasks = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listTasks ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listTasks as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listTasks with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listTasks = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listTasks ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listTasks as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listTasksStream without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , ] ; client . descriptors . page . listTasks . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listTasksStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; const responses = await promise ; assert . deepStrictEqual ( responses , expectedResponse ) ; assert ( ( client . descriptors . page . listTasks . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listTasks , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listTasks . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listTasksStream with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listTasks . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listTasksStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; stream . on ( 'data' , ( response ) => { responses . push ( response ) ; } ) ; stream . on ( 'end' , ( ) => { resolve ( responses ) ; } ) ; stream . on ( 'error' , ( err ) => { reject ( err ) ; } ) ; } ) ; await assert . rejects ( promise , expectedError ) ; assert ( ( client . descriptors . page . listTasks . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listTasks , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listTasks . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listTasks without error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , generateSampleMessage ( new protos . google . cloud . tasks . v2 . Task ( ) ) , ] ; client . descriptors . page . listTasks . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listTasksAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listTasks . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listTasks . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listTasks with error' , async ( ) => { const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . tasks . v2 . ListTasksRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listTasks . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listTasksAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listTasks . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listTasks . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'Path templates' , ( ) => { describe ( 'location' , ( ) => { const fakePath = '/rendered/path/location' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , } ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . locationPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . locationPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'locationPath' , ( ) => { const result = client . locationPath ( 'projectValue' , 'locationValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . locationPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromLocationName' , ( ) => { const result = client . matchProjectFromLocationName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . locationPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromLocationName' , ( ) => { const result = client . matchLocationFromLocationName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . locationPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'project' , ( ) => { const fakePath = '/rendered/path/project' ; const expectedParameters = { project : 'projectValue' , } ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . projectPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . projectPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'projectPath' , ( ) => { const result = client . projectPath ( 'projectValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . projectPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromProjectName' , ( ) => { const result = client . matchProjectFromProjectName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . projectPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'queue' , ( ) => { const fakePath = '/rendered/path/queue' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , queue : 'queueValue' , } ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . queuePathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . queuePathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'queuePath' , ( ) => { const result = client . queuePath ( 'projectValue' , 'locationValue' , 'queueValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . queuePathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromQueueName' , ( ) => { const result = client . matchProjectFromQueueName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . queuePathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromQueueName' , ( ) => { const result = client . matchLocationFromQueueName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . queuePathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchQueueFromQueueName' , ( ) => { const result = client . matchQueueFromQueueName ( fakePath ) ; assert . strictEqual ( result , 'queueValue' ) ; assert ( ( client . pathTemplates . queuePathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'task' , ( ) => { const fakePath = '/rendered/path/task' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , queue : 'queueValue' , task : 'taskValue' , } ; const client = new cloudtasksModule . v2 . CloudTasksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . taskPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . taskPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'taskPath' , ( ) => { const result = client . taskPath ( 'projectValue' , 'locationValue' , 'queueValue' , 'taskValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . taskPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromTaskName' , ( ) => { const result = client . matchProjectFromTaskName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . taskPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromTaskName' , ( ) => { const result = client . matchLocationFromTaskName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . taskPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchQueueFromTaskName' , ( ) => { const result = client . matchQueueFromTaskName ( fakePath ) ; assert . strictEqual ( result , 'queueValue' ) ; assert ( ( client . pathTemplates . taskPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchTaskFromTaskName' , ( ) => { const result = client . matchTaskFromTaskName ( fakePath ) ; assert . strictEqual ( result , 'taskValue' ) ; assert ( ( client . pathTemplates . taskPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; } ) ; } ) ;