import * as protos from '../protos/protos' ; import * as assert from 'assert' ; import * as sinon from 'sinon' ; import { SinonStub } from 'sinon' ; import { describe , it , beforeEach , afterEach } from 'mocha' ; import * as regioninstancegroupmanagersModule from '../src' ; import { PassThrough } from 'stream' ; import { GoogleAuth , 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 ( 'v1.RegionInstanceGroupManagersClient' , ( ) => { let googleAuth ; beforeEach ( ( ) => { googleAuth = { getClient : sinon . stub ( ) . resolves ( { getRequestHeaders : sinon . stub ( ) . resolves ( { Authorization : 'Bearer SOME_TOKEN' } ) , } ) , } as unknown as GoogleAuth ; } ) ; afterEach ( ( ) => { sinon . restore ( ) ; } ) ; it ( 'has servicePath' , ( ) => { const servicePath = regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; assert . strictEqual ( client . regionInstanceGroupManagersStub , undefined ) ; await client . initialize ( ) ; assert ( client . regionInstanceGroupManagersStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . resolves ( fakeProjectId ) ; const result = await client . getProjectId ( ) ; assert . strictEqual ( result , fakeProjectId ) ; assert ( ( client . auth . getProjectId as SinonStub ) . calledWithExactly ( ) ) ; } ) ; it ( 'has getProjectId method with callback' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , 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 ( 'abandonInstances' , ( ) => { it ( 'invokes abandonInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . AbandonInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . abandonInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . abandonInstances ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . abandonInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes abandonInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . AbandonInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . abandonInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . abandonInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . abandonInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes abandonInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . AbandonInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . abandonInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . abandonInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . abandonInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'applyUpdatesToInstances' , ( ) => { it ( 'invokes applyUpdatesToInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . applyUpdatesToInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . applyUpdatesToInstances ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . applyUpdatesToInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes applyUpdatesToInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . applyUpdatesToInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . applyUpdatesToInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . applyUpdatesToInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes applyUpdatesToInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ApplyUpdatesToInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . applyUpdatesToInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . applyUpdatesToInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . applyUpdatesToInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'createInstances' , ( ) => { it ( 'invokes createInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . CreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . createInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createInstances ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . createInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . CreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . createInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . CreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'delete' , ( ) => { it ( 'invokes delete without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . delete = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . delete ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . delete as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes delete without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . delete = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . delete ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . delete as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes delete with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . delete = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . delete ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . delete as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteInstances' , ( ) => { it ( 'invokes deleteInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . deleteInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteInstances ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . deleteInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deletePerInstanceConfigs' , ( ) => { it ( 'invokes deletePerInstanceConfigs without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeletePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . deletePerInstanceConfigs = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deletePerInstanceConfigs ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . deletePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deletePerInstanceConfigs without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeletePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . deletePerInstanceConfigs = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deletePerInstanceConfigs ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deletePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deletePerInstanceConfigs with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeletePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deletePerInstanceConfigs = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deletePerInstanceConfigs ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deletePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'get' , ( ) => { it ( 'invokes get without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) ; client . innerApiCalls . get = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . get ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . get as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes get without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) ; client . innerApiCalls . get = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . get ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . get as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes get with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . get = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . get ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . get as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'insert' , ( ) => { it ( 'invokes insert without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . insert = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . insert ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . insert as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes insert without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . insert = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . insert ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . insert as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes insert with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . insert = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . insert ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . insert as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'patch' , ( ) => { it ( 'invokes patch without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . patch = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . patch ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . patch as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes patch without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . patch = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . patch ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . patch as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes patch with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . patch = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . patch ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . patch as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'patchPerInstanceConfigs' , ( ) => { it ( 'invokes patchPerInstanceConfigs without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchPerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . patchPerInstanceConfigs = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . patchPerInstanceConfigs ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . patchPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes patchPerInstanceConfigs without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchPerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . patchPerInstanceConfigs = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . patchPerInstanceConfigs ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . patchPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes patchPerInstanceConfigs with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchPerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . patchPerInstanceConfigs = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . patchPerInstanceConfigs ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . patchPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'recreateInstances' , ( ) => { it ( 'invokes recreateInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . RecreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . recreateInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . recreateInstances ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . recreateInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes recreateInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . RecreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . recreateInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . recreateInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . recreateInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes recreateInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . RecreateInstancesRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . recreateInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . recreateInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . recreateInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'resize' , ( ) => { it ( 'invokes resize without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ResizeRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . resize = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . resize ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . resize as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes resize without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ResizeRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . resize = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . resize ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . resize as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes resize with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ResizeRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . resize = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . resize ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . resize as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'setInstanceTemplate' , ( ) => { it ( 'invokes setInstanceTemplate without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetInstanceTemplateRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . setInstanceTemplate = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setInstanceTemplate ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . setInstanceTemplate as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setInstanceTemplate without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetInstanceTemplateRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . setInstanceTemplate = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setInstanceTemplate ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setInstanceTemplate as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setInstanceTemplate with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetInstanceTemplateRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setInstanceTemplate = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setInstanceTemplate ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setInstanceTemplate as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'setTargetPools' , ( ) => { it ( 'invokes setTargetPools without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetTargetPoolsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . setTargetPools = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setTargetPools ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . setTargetPools as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setTargetPools without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetTargetPoolsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . setTargetPools = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setTargetPools ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setTargetPools as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setTargetPools with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetTargetPoolsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setTargetPools = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setTargetPools ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setTargetPools as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updatePerInstanceConfigs' , ( ) => { it ( 'invokes updatePerInstanceConfigs without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . updatePerInstanceConfigs = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updatePerInstanceConfigs ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . updatePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updatePerInstanceConfigs without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Operation ( ) ) ; client . innerApiCalls . updatePerInstanceConfigs = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updatePerInstanceConfigs ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updatePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updatePerInstanceConfigs with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . UpdatePerInstanceConfigsRegionInstanceGroupManagerRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updatePerInstanceConfigs = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updatePerInstanceConfigs ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updatePerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'list' , ( ) => { it ( 'invokes list without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , ] ; client . innerApiCalls . list = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . list ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . list as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes list without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , ] ; client . innerApiCalls . list = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . list ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . list as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes list with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . list = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . list ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . list as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listStream without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , ] ; client . descriptors . page . list . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listStream ( 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 . list . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . list , request ) ) ; assert . strictEqual ( ( client . descriptors . page . list . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listStream with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . list . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listStream ( request ) ; const promise = new Promise ( ( resolve , reject ) => { const responses = [ ] ; 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 . list . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . list , request ) ) ; assert . strictEqual ( ( client . descriptors . page . list . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with list without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceGroupManager ( ) ) , ] ; client . descriptors . page . list . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . list . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . list . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with list with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . list . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . list . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . list . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listErrors' , ( ) => { it ( 'invokes listErrors without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , ] ; client . innerApiCalls . listErrors = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listErrors ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listErrors as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listErrors without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , ] ; client . innerApiCalls . listErrors = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listErrors ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listErrors as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listErrors with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listErrors = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listErrors ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listErrors as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listErrorsStream without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , ] ; client . descriptors . page . listErrors . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listErrorsStream ( 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 . listErrors . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listErrors , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listErrors . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listErrorsStream with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listErrors . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listErrorsStream ( 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 . listErrors . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listErrors , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listErrors . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listErrors without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . InstanceManagedByIgmError ( ) ) , ] ; client . descriptors . page . listErrors . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listErrorsAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listErrors . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listErrors . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listErrors with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListErrorsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listErrors . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listErrorsAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listErrors . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listErrors . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listManagedInstances' , ( ) => { it ( 'invokes listManagedInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , ] ; client . innerApiCalls . listManagedInstances = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listManagedInstances ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listManagedInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listManagedInstances without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , ] ; client . innerApiCalls . listManagedInstances = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listManagedInstances ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listManagedInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listManagedInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listManagedInstances = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listManagedInstances ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listManagedInstances as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listManagedInstancesStream without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , ] ; client . descriptors . page . listManagedInstances . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listManagedInstancesStream ( 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 . listManagedInstances . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listManagedInstances , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listManagedInstances . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listManagedInstancesStream with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listManagedInstances . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listManagedInstancesStream ( 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 . listManagedInstances . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listManagedInstances , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listManagedInstances . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listManagedInstances without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . ManagedInstance ( ) ) , ] ; client . descriptors . page . listManagedInstances . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listManagedInstancesAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listManagedInstances . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listManagedInstances . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listManagedInstances with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListManagedInstancesRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listManagedInstances . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listManagedInstancesAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listManagedInstances . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listManagedInstances . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listPerInstanceConfigs' , ( ) => { it ( 'invokes listPerInstanceConfigs without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , ] ; client . innerApiCalls . listPerInstanceConfigs = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listPerInstanceConfigs ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listPerInstanceConfigs without error using callback' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , ] ; client . innerApiCalls . listPerInstanceConfigs = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listPerInstanceConfigs ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listPerInstanceConfigs with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listPerInstanceConfigs = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listPerInstanceConfigs ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listPerInstanceConfigs as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listPerInstanceConfigsStream without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , ] ; client . descriptors . page . listPerInstanceConfigs . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listPerInstanceConfigsStream ( 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 . listPerInstanceConfigs . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listPerInstanceConfigs , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listPerInstanceConfigs . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listPerInstanceConfigsStream with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listPerInstanceConfigs . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listPerInstanceConfigsStream ( 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 . listPerInstanceConfigs . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listPerInstanceConfigs , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listPerInstanceConfigs . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listPerInstanceConfigs without error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . PerInstanceConfig ( ) ) , ] ; client . descriptors . page . listPerInstanceConfigs . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listPerInstanceConfigsAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listPerInstanceConfigs . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listPerInstanceConfigs . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listPerInstanceConfigs with error' , async ( ) => { const client = new regioninstancegroupmanagersModule . v1 . RegionInstanceGroupManagersClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListPerInstanceConfigsRegionInstanceGroupManagersRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listPerInstanceConfigs . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listPerInstanceConfigsAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listPerInstanceConfigs . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listPerInstanceConfigs . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; } ) ;