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 subnetworksModule 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.SubnetworksClient' , ( ) => { 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 = subnetworksModule . v1 . SubnetworksClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = subnetworksModule . v1 . SubnetworksClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = subnetworksModule . v1 . SubnetworksClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; assert . strictEqual ( client . subnetworksStub , undefined ) ; await client . initialize ( ) ; assert ( client . subnetworksStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new subnetworksModule . v1 . SubnetworksClient ( { 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 subnetworksModule . v1 . SubnetworksClient ( { 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 ( 'delete' , ( ) => { it ( 'invokes delete without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . DeleteSubnetworkRequest ( ) ) ; 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 ( 'expandIpCidrRange' , ( ) => { it ( 'invokes expandIpCidrRange without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ExpandIpCidrRangeSubnetworkRequest ( ) ) ; 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 . expandIpCidrRange = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . expandIpCidrRange ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . expandIpCidrRange as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes expandIpCidrRange without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ExpandIpCidrRangeSubnetworkRequest ( ) ) ; 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 . expandIpCidrRange = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . expandIpCidrRange ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . expandIpCidrRange as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes expandIpCidrRange with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ExpandIpCidrRangeSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . expandIpCidrRange = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . expandIpCidrRange ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . expandIpCidrRange as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'get' , ( ) => { it ( 'invokes get without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetSubnetworkRequest ( ) ) ; 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 ( 'getIamPolicy' , ( ) => { it ( 'invokes getIamPolicy without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getIamPolicy without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getIamPolicy with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . GetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'insert' , ( ) => { it ( 'invokes insert without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . InsertSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchSubnetworkRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . PatchSubnetworkRequest ( ) ) ; 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 ( 'setIamPolicy' , ( ) => { it ( 'invokes setIamPolicy without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setIamPolicy without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setIamPolicy with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetIamPolicySubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'setPrivateIpGoogleAccess' , ( ) => { it ( 'invokes setPrivateIpGoogleAccess without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetPrivateIpGoogleAccessSubnetworkRequest ( ) ) ; 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 . setPrivateIpGoogleAccess = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setPrivateIpGoogleAccess ( request ) ; assert . deepStrictEqual ( response . latestResponse , expectedResponse ) ; assert ( ( client . innerApiCalls . setPrivateIpGoogleAccess as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setPrivateIpGoogleAccess without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetPrivateIpGoogleAccessSubnetworkRequest ( ) ) ; 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 . setPrivateIpGoogleAccess = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setPrivateIpGoogleAccess ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setPrivateIpGoogleAccess as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setPrivateIpGoogleAccess with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . SetPrivateIpGoogleAccessSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setPrivateIpGoogleAccess = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setPrivateIpGoogleAccess ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setPrivateIpGoogleAccess as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'testIamPermissions' , ( ) => { it ( 'invokes testIamPermissions without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . TestIamPermissionsSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . TestPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . testIamPermissions ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes testIamPermissions without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . TestIamPermissionsSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . compute . v1 . TestPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . testIamPermissions ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes testIamPermissions with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . TestIamPermissionsSubnetworkRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . testIamPermissions ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'aggregatedList' , ( ) => { it ( 'uses async iteration with aggregatedList without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . AggregatedListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ [ 'tuple_key_1' , generateSampleMessage ( new protos . google . cloud . compute . v1 . SubnetworksScopedList ( ) ) , ] , [ 'tuple_key_2' , generateSampleMessage ( new protos . google . cloud . compute . v1 . SubnetworksScopedList ( ) ) , ] , [ 'tuple_key_3' , generateSampleMessage ( new protos . google . cloud . compute . v1 . SubnetworksScopedList ( ) ) , ] , ] ; client . descriptors . page . aggregatedList . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . aggregatedListAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . aggregatedList . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . aggregatedList . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with aggregatedList with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . AggregatedListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . aggregatedList . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . aggregatedListAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . aggregatedList . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . aggregatedList . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'list' , ( ) => { it ( 'invokes list without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , ] ; 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 subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , ] ; 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 subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , ] ; 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 subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; 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 subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . Subnetwork ( ) ) , ] ; 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 subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListSubnetworksRequest ( ) ) ; 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 ( 'listUsable' , ( ) => { it ( 'invokes listUsable without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , ] ; client . innerApiCalls . listUsable = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listUsable ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listUsable as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listUsable without error using callback' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , ] ; client . innerApiCalls . listUsable = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listUsable ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listUsable as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listUsable with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listUsable = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listUsable ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listUsable as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listUsableStream without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , ] ; client . descriptors . page . listUsable . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listUsableStream ( 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 . listUsable . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listUsable , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listUsable . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listUsableStream with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listUsable . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listUsableStream ( 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 . listUsable . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listUsable , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listUsable . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listUsable without error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { auth : googleAuth , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , generateSampleMessage ( new protos . google . cloud . compute . v1 . UsableSubnetwork ( ) ) , ] ; client . descriptors . page . listUsable . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listUsableAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listUsable . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listUsable . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listUsable with error' , async ( ) => { const client = new subnetworksModule . v1 . SubnetworksClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . compute . v1 . ListUsableSubnetworksRequest ( ) ) ; request . project = '' ; const expectedHeaderRequestParams = 'project=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listUsable . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listUsableAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listUsable . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listUsable . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; } ) ;