import * as protos from '../protos/protos' ; import * as assert from 'assert' ; import * as sinon from 'sinon' ; import { SinonStub } from 'sinon' ; import { describe , it } from 'mocha' ; import * as assetserviceModule from '../src' ; import { PassThrough } from 'stream' ; import { protobuf , LROperation , operationsProtos } 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 stubLongRunningCall < ResponseType > ( response ? , callError ? , lroError ? ) { const innerStub = lroError ? sinon . stub ( ) . rejects ( lroError ) : sinon . stub ( ) . resolves ( [ response ] ) ; const mockOperation = { promise : innerStub , } ; return callError ? sinon . stub ( ) . rejects ( callError ) : sinon . stub ( ) . resolves ( [ mockOperation ] ) ; } function stubLongRunningCallWithCallback < ResponseType > ( response ? , callError ? , lroError ? ) { const innerStub = lroError ? sinon . stub ( ) . rejects ( lroError ) : sinon . stub ( ) . resolves ( [ response ] ) ; const mockOperation = { promise : innerStub , } ; return callError ? sinon . stub ( ) . callsArgWith ( 2 , callError ) : sinon . stub ( ) . callsArgWith ( 2 , null , mockOperation ) ; } function stubPageStreamingCall < 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.AssetServiceClient' , ( ) => { it ( 'has servicePath' , ( ) => { const servicePath = assetserviceModule . v1 . AssetServiceClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = assetserviceModule . v1 . AssetServiceClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = assetserviceModule . v1 . AssetServiceClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; assert . strictEqual ( client . assetServiceStub , undefined ) ; await client . initialize ( ) ; assert ( client . assetServiceStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . resolves ( fakeProjectId ) ; const result = await client . getProjectId ( ) ; assert . strictEqual ( result , fakeProjectId ) ; assert ( ( client . auth . getProjectId as SinonStub ) . calledWithExactly ( ) ) ; } ) ; it ( 'has getProjectId method with callback' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . auth . getProjectId = sinon . stub ( ) . callsArgWith ( 0 , null , fakeProjectId ) ; const promise = new Promise ( ( resolve , reject ) => { client . getProjectId ( ( err ? , projectId ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( projectId ) ; } } ) ; } ) ; const result = await promise ; assert . strictEqual ( result , fakeProjectId ) ; } ) ; describe ( 'batchGetAssetsHistory' , ( ) => { it ( 'invokes batchGetAssetsHistory without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . BatchGetAssetsHistoryRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . BatchGetAssetsHistoryResponse ( ) ) ; client . innerApiCalls . batchGetAssetsHistory = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . batchGetAssetsHistory ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . batchGetAssetsHistory as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes batchGetAssetsHistory without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . BatchGetAssetsHistoryRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . BatchGetAssetsHistoryResponse ( ) ) ; client . innerApiCalls . batchGetAssetsHistory = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . batchGetAssetsHistory ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . batchGetAssetsHistory as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes batchGetAssetsHistory with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . BatchGetAssetsHistoryRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . batchGetAssetsHistory = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . batchGetAssetsHistory ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . batchGetAssetsHistory as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'createFeed' , ( ) => { it ( 'invokes createFeed without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . CreateFeedRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . createFeed = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createFeed ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createFeed without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . CreateFeedRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . createFeed = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createFeed ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createFeed with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . CreateFeedRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createFeed = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createFeed ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getFeed' , ( ) => { it ( 'invokes getFeed without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . GetFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . getFeed = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getFeed ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getFeed without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . GetFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . getFeed = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getFeed ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getFeed with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . GetFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getFeed = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getFeed ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'listFeeds' , ( ) => { it ( 'invokes listFeeds without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListFeedsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListFeedsResponse ( ) ) ; client . innerApiCalls . listFeeds = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listFeeds ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listFeeds as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listFeeds without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListFeedsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListFeedsResponse ( ) ) ; client . innerApiCalls . listFeeds = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listFeeds ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listFeeds as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listFeeds with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListFeedsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listFeeds = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listFeeds ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listFeeds as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updateFeed' , ( ) => { it ( 'invokes updateFeed without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . UpdateFeedRequest ( ) ) ; request . feed = { } ; request . feed . name = '' ; const expectedHeaderRequestParams = 'feed.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . updateFeed = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updateFeed ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updateFeed without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . UpdateFeedRequest ( ) ) ; request . feed = { } ; request . feed . name = '' ; const expectedHeaderRequestParams = 'feed.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . Feed ( ) ) ; client . innerApiCalls . updateFeed = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updateFeed ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updateFeed with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . UpdateFeedRequest ( ) ) ; request . feed = { } ; request . feed . name = '' ; const expectedHeaderRequestParams = 'feed.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updateFeed = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updateFeed ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updateFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteFeed' , ( ) => { it ( 'invokes deleteFeed without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . DeleteFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteFeed = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteFeed ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteFeed without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . DeleteFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteFeed = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteFeed ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteFeed with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . DeleteFeedRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteFeed = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteFeed ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteFeed as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'analyzeIamPolicy' , ( ) => { it ( 'invokes analyzeIamPolicy without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyResponse ( ) ) ; client . innerApiCalls . analyzeIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . analyzeIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes analyzeIamPolicy without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyResponse ( ) ) ; client . innerApiCalls . analyzeIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . analyzeIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes analyzeIamPolicy with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . analyzeIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . analyzeIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . analyzeIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'analyzeMove' , ( ) => { it ( 'invokes analyzeMove without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeMoveRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeMoveResponse ( ) ) ; client . innerApiCalls . analyzeMove = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . analyzeMove ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeMove as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes analyzeMove without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeMoveRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeMoveResponse ( ) ) ; client . innerApiCalls . analyzeMove = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . analyzeMove ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeMove as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes analyzeMove with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeMoveRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . analyzeMove = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . analyzeMove ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . analyzeMove as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'exportAssets' , ( ) => { it ( 'invokes exportAssets without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ExportAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . longrunning . Operation ( ) ) ; client . innerApiCalls . exportAssets = stubLongRunningCall ( expectedResponse ) ; const [ operation ] = await client . exportAssets ( request ) ; const [ response ] = await operation . promise ( ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . exportAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes exportAssets without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ExportAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . longrunning . Operation ( ) ) ; client . innerApiCalls . exportAssets = stubLongRunningCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . exportAssets ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const operation = ( await promise ) as LROperation < protos . google . cloud . asset . v1 . IExportAssetsResponse , protos . google . cloud . asset . v1 . IExportAssetsRequest > ; const [ response ] = await operation . promise ( ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . exportAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes exportAssets with call error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ExportAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . exportAssets = stubLongRunningCall ( undefined , expectedError ) ; await assert . rejects ( client . exportAssets ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . exportAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes exportAssets with LRO error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ExportAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . exportAssets = stubLongRunningCall ( undefined , undefined , expectedError ) ; const [ operation ] = await client . exportAssets ( request ) ; await assert . rejects ( operation . promise ( ) , expectedError ) ; assert ( ( client . innerApiCalls . exportAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes checkExportAssetsProgress without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const expectedResponse = generateSampleMessage ( new operationsProtos . google . longrunning . Operation ( ) ) ; expectedResponse . name = 'test' ; expectedResponse . response = { type_url : 'url' , value : Buffer . from ( '' ) } ; expectedResponse . metadata = { type_url : 'url' , value : Buffer . from ( '' ) } ; client . operationsClient . getOperation = stubSimpleCall ( expectedResponse ) ; const decodedOperation = await client . checkExportAssetsProgress ( expectedResponse . name ) ; assert . deepStrictEqual ( decodedOperation . name , expectedResponse . name ) ; assert ( decodedOperation . metadata ) ; assert ( ( client . operationsClient . getOperation as SinonStub ) . getCall ( 0 ) ) ; } ) ; it ( 'invokes checkExportAssetsProgress with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const expectedError = new Error ( 'expected' ) ; client . operationsClient . getOperation = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . checkExportAssetsProgress ( '' ) , expectedError ) ; assert ( ( client . operationsClient . getOperation as SinonStub ) . getCall ( 0 ) ) ; } ) ; } ) ; describe ( 'analyzeIamPolicyLongrunning' , ( ) => { it ( 'invokes analyzeIamPolicyLongrunning without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyLongrunningRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . longrunning . Operation ( ) ) ; client . innerApiCalls . analyzeIamPolicyLongrunning = stubLongRunningCall ( expectedResponse ) ; const [ operation ] = await client . analyzeIamPolicyLongrunning ( request ) ; const [ response ] = await operation . promise ( ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeIamPolicyLongrunning as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes analyzeIamPolicyLongrunning without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyLongrunningRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . longrunning . Operation ( ) ) ; client . innerApiCalls . analyzeIamPolicyLongrunning = stubLongRunningCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . analyzeIamPolicyLongrunning ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const operation = ( await promise ) as LROperation < protos . google . cloud . asset . v1 . IAnalyzeIamPolicyLongrunningResponse , protos . google . cloud . asset . v1 . IAnalyzeIamPolicyLongrunningMetadata > ; const [ response ] = await operation . promise ( ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . analyzeIamPolicyLongrunning as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes analyzeIamPolicyLongrunning with call error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyLongrunningRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . analyzeIamPolicyLongrunning = stubLongRunningCall ( undefined , expectedError ) ; await assert . rejects ( client . analyzeIamPolicyLongrunning ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . analyzeIamPolicyLongrunning as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes analyzeIamPolicyLongrunning with LRO error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . AnalyzeIamPolicyLongrunningRequest ( ) ) ; request . analysisQuery = { } ; request . analysisQuery . scope = '' ; const expectedHeaderRequestParams = 'analysis_query.scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . analyzeIamPolicyLongrunning = stubLongRunningCall ( undefined , undefined , expectedError ) ; const [ operation ] = await client . analyzeIamPolicyLongrunning ( request ) ; await assert . rejects ( operation . promise ( ) , expectedError ) ; assert ( ( client . innerApiCalls . analyzeIamPolicyLongrunning as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes checkAnalyzeIamPolicyLongrunningProgress without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const expectedResponse = generateSampleMessage ( new operationsProtos . google . longrunning . Operation ( ) ) ; expectedResponse . name = 'test' ; expectedResponse . response = { type_url : 'url' , value : Buffer . from ( '' ) } ; expectedResponse . metadata = { type_url : 'url' , value : Buffer . from ( '' ) } ; client . operationsClient . getOperation = stubSimpleCall ( expectedResponse ) ; const decodedOperation = await client . checkAnalyzeIamPolicyLongrunningProgress ( expectedResponse . name ) ; assert . deepStrictEqual ( decodedOperation . name , expectedResponse . name ) ; assert ( decodedOperation . metadata ) ; assert ( ( client . operationsClient . getOperation as SinonStub ) . getCall ( 0 ) ) ; } ) ; it ( 'invokes checkAnalyzeIamPolicyLongrunningProgress with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const expectedError = new Error ( 'expected' ) ; client . operationsClient . getOperation = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . checkAnalyzeIamPolicyLongrunningProgress ( '' ) , expectedError ) ; assert ( ( client . operationsClient . getOperation as SinonStub ) . getCall ( 0 ) ) ; } ) ; } ) ; describe ( 'listAssets' , ( ) => { it ( 'invokes listAssets without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , ] ; client . innerApiCalls . listAssets = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listAssets ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listAssets without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , ] ; client . innerApiCalls . listAssets = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listAssets ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listAssets with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listAssets = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listAssets ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listAssets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listAssetsStream without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , ] ; client . descriptors . page . listAssets . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listAssetsStream ( 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 . listAssets . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listAssets , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listAssets . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listAssetsStream with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listAssets . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listAssetsStream ( 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 . listAssets . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listAssets , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listAssets . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listAssets without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . Asset ( ) ) , ] ; client . descriptors . page . listAssets . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listAssetsAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listAssets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listAssets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listAssets with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . ListAssetsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listAssets . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listAssetsAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listAssets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listAssets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'searchAllResources' , ( ) => { it ( 'invokes searchAllResources without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , ] ; client . innerApiCalls . searchAllResources = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . searchAllResources ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . searchAllResources as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes searchAllResources without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , ] ; client . innerApiCalls . searchAllResources = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . searchAllResources ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . searchAllResources as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes searchAllResources with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . searchAllResources = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . searchAllResources ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . searchAllResources as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes searchAllResourcesStream without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , ] ; client . descriptors . page . searchAllResources . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . searchAllResourcesStream ( 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 . searchAllResources . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . searchAllResources , request ) ) ; assert . strictEqual ( ( client . descriptors . page . searchAllResources . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes searchAllResourcesStream with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . searchAllResources . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . searchAllResourcesStream ( 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 . searchAllResources . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . searchAllResources , request ) ) ; assert . strictEqual ( ( client . descriptors . page . searchAllResources . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with searchAllResources without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . ResourceSearchResult ( ) ) , ] ; client . descriptors . page . searchAllResources . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . searchAllResourcesAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . searchAllResources . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . searchAllResources . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with searchAllResources with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllResourcesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . searchAllResources . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . searchAllResourcesAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . searchAllResources . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . searchAllResources . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'searchAllIamPolicies' , ( ) => { it ( 'invokes searchAllIamPolicies without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , ] ; client . innerApiCalls . searchAllIamPolicies = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . searchAllIamPolicies ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . searchAllIamPolicies as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes searchAllIamPolicies without error using callback' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , ] ; client . innerApiCalls . searchAllIamPolicies = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . searchAllIamPolicies ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . searchAllIamPolicies as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes searchAllIamPolicies with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . searchAllIamPolicies = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . searchAllIamPolicies ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . searchAllIamPolicies as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes searchAllIamPoliciesStream without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , ] ; client . descriptors . page . searchAllIamPolicies . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . searchAllIamPoliciesStream ( 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 . searchAllIamPolicies . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . searchAllIamPolicies , request ) ) ; assert . strictEqual ( ( client . descriptors . page . searchAllIamPolicies . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes searchAllIamPoliciesStream with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . searchAllIamPolicies . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . searchAllIamPoliciesStream ( 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 . searchAllIamPolicies . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . searchAllIamPolicies , request ) ) ; assert . strictEqual ( ( client . descriptors . page . searchAllIamPolicies . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with searchAllIamPolicies without error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , generateSampleMessage ( new protos . google . cloud . asset . v1 . IamPolicySearchResult ( ) ) , ] ; client . descriptors . page . searchAllIamPolicies . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . searchAllIamPoliciesAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . searchAllIamPolicies . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . searchAllIamPolicies . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with searchAllIamPolicies with error' , async ( ) => { const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . asset . v1 . SearchAllIamPoliciesRequest ( ) ) ; request . scope = '' ; const expectedHeaderRequestParams = 'scope=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . searchAllIamPolicies . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . searchAllIamPoliciesAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . searchAllIamPolicies . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . searchAllIamPolicies . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'Path templates' , ( ) => { describe ( 'accessLevel' , ( ) => { const fakePath = '/rendered/path/accessLevel' ; const expectedParameters = { access_policy : 'accessPolicyValue' , access_level : 'accessLevelValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . accessLevelPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . accessLevelPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'accessLevelPath' , ( ) => { const result = client . accessLevelPath ( 'accessPolicyValue' , 'accessLevelValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . accessLevelPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchAccessPolicyFromAccessLevelName' , ( ) => { const result = client . matchAccessPolicyFromAccessLevelName ( fakePath ) ; assert . strictEqual ( result , 'accessPolicyValue' ) ; assert ( ( client . pathTemplates . accessLevelPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchAccessLevelFromAccessLevelName' , ( ) => { const result = client . matchAccessLevelFromAccessLevelName ( fakePath ) ; assert . strictEqual ( result , 'accessLevelValue' ) ; assert ( ( client . pathTemplates . accessLevelPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'accessPolicy' , ( ) => { const fakePath = '/rendered/path/accessPolicy' ; const expectedParameters = { access_policy : 'accessPolicyValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . accessPolicyPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . accessPolicyPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'accessPolicyPath' , ( ) => { const result = client . accessPolicyPath ( 'accessPolicyValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . accessPolicyPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchAccessPolicyFromAccessPolicyName' , ( ) => { const result = client . matchAccessPolicyFromAccessPolicyName ( fakePath ) ; assert . strictEqual ( result , 'accessPolicyValue' ) ; assert ( ( client . pathTemplates . accessPolicyPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'folderFeed' , ( ) => { const fakePath = '/rendered/path/folderFeed' ; const expectedParameters = { folder : 'folderValue' , feed : 'feedValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . folderFeedPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . folderFeedPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'folderFeedPath' , ( ) => { const result = client . folderFeedPath ( 'folderValue' , 'feedValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . folderFeedPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchFolderFromFolderFeedName' , ( ) => { const result = client . matchFolderFromFolderFeedName ( fakePath ) ; assert . strictEqual ( result , 'folderValue' ) ; assert ( ( client . pathTemplates . folderFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchFeedFromFolderFeedName' , ( ) => { const result = client . matchFeedFromFolderFeedName ( fakePath ) ; assert . strictEqual ( result , 'feedValue' ) ; assert ( ( client . pathTemplates . folderFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'inventory' , ( ) => { const fakePath = '/rendered/path/inventory' ; const expectedParameters = { project : 'projectValue' , location : 'locationValue' , instance : 'instanceValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . inventoryPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . inventoryPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'inventoryPath' , ( ) => { const result = client . inventoryPath ( 'projectValue' , 'locationValue' , 'instanceValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . inventoryPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromInventoryName' , ( ) => { const result = client . matchProjectFromInventoryName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . inventoryPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchLocationFromInventoryName' , ( ) => { const result = client . matchLocationFromInventoryName ( fakePath ) ; assert . strictEqual ( result , 'locationValue' ) ; assert ( ( client . pathTemplates . inventoryPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchInstanceFromInventoryName' , ( ) => { const result = client . matchInstanceFromInventoryName ( fakePath ) ; assert . strictEqual ( result , 'instanceValue' ) ; assert ( ( client . pathTemplates . inventoryPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'organizationFeed' , ( ) => { const fakePath = '/rendered/path/organizationFeed' ; const expectedParameters = { organization : 'organizationValue' , feed : 'feedValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . organizationFeedPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . organizationFeedPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'organizationFeedPath' , ( ) => { const result = client . organizationFeedPath ( 'organizationValue' , 'feedValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . organizationFeedPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchOrganizationFromOrganizationFeedName' , ( ) => { const result = client . matchOrganizationFromOrganizationFeedName ( fakePath ) ; assert . strictEqual ( result , 'organizationValue' ) ; assert ( ( client . pathTemplates . organizationFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchFeedFromOrganizationFeedName' , ( ) => { const result = client . matchFeedFromOrganizationFeedName ( fakePath ) ; assert . strictEqual ( result , 'feedValue' ) ; assert ( ( client . pathTemplates . organizationFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'projectFeed' , ( ) => { const fakePath = '/rendered/path/projectFeed' ; const expectedParameters = { project : 'projectValue' , feed : 'feedValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . projectFeedPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . projectFeedPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'projectFeedPath' , ( ) => { const result = client . projectFeedPath ( 'projectValue' , 'feedValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . projectFeedPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromProjectFeedName' , ( ) => { const result = client . matchProjectFromProjectFeedName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . projectFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchFeedFromProjectFeedName' , ( ) => { const result = client . matchFeedFromProjectFeedName ( fakePath ) ; assert . strictEqual ( result , 'feedValue' ) ; assert ( ( client . pathTemplates . projectFeedPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'servicePerimeter' , ( ) => { const fakePath = '/rendered/path/servicePerimeter' ; const expectedParameters = { access_policy : 'accessPolicyValue' , service_perimeter : 'servicePerimeterValue' , } ; const client = new assetserviceModule . v1 . AssetServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . servicePerimeterPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . servicePerimeterPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'servicePerimeterPath' , ( ) => { const result = client . servicePerimeterPath ( 'accessPolicyValue' , 'servicePerimeterValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . servicePerimeterPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchAccessPolicyFromServicePerimeterName' , ( ) => { const result = client . matchAccessPolicyFromServicePerimeterName ( fakePath ) ; assert . strictEqual ( result , 'accessPolicyValue' ) ; assert ( ( client . pathTemplates . servicePerimeterPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchServicePerimeterFromServicePerimeterName' , ( ) => { const result = client . matchServicePerimeterFromServicePerimeterName ( fakePath ) ; assert . strictEqual ( result , 'servicePerimeterValue' ) ; assert ( ( client . pathTemplates . servicePerimeterPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; } ) ; } ) ;