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 secretmanagerserviceModule from '../src' ; import { PassThrough } from 'stream' ; import { protobuf } from 'google-gax' ; function generateSampleMessage < T extends object > ( instance ) { const filledObject = ( instance . constructor as typeof protobuf . Message ) . toObject ( instance as protobuf . Message < T > , { defaults : true } ) ; return ( instance . constructor as typeof protobuf . Message ) . fromObject ( filledObject ) as T ; } function stubSimpleCall < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . rejects ( error ) : sinon . stub ( ) . resolves ( [ response ] ) ; } function stubSimpleCallWithCallback < ResponseType > ( response ? , error ? ) { return error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : sinon . stub ( ) . callsArgWith ( 2 , null , response ) ; } function stubPageStreamingCall < ResponseType > ( responses ? , error ? ) { const pagingStub = sinon . stub ( ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { pagingStub . onCall ( i ) . callsArgWith ( 2 , null , responses [ i ] ) ; } } const transformStub = error ? sinon . stub ( ) . callsArgWith ( 2 , error ) : pagingStub ; const mockStream = new PassThrough ( { objectMode : true , transform : transformStub , } ) ; if ( responses ) { for ( let i = 0 ; i < responses . length ; ++ i ) { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; } setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } else { setImmediate ( ( ) => { mockStream . write ( { } ) ; } ) ; setImmediate ( ( ) => { mockStream . end ( ) ; } ) ; } return sinon . stub ( ) . returns ( mockStream ) ; } function stubAsyncIterationCall < ResponseType > ( responses ? , error ? ) { let counter = 0 ; const asyncIterable = { [ Symbol . asyncIterator ] ( ) { return { async next ( ) { if ( error ) { return Promise . reject ( error ) ; } if ( counter >= responses ! . length ) { return Promise . resolve ( { done : true , value : undefined } ) ; } return Promise . resolve ( { done : false , value : responses ! [ counter ++ ] } ) ; } , } ; } , } ; return sinon . stub ( ) . returns ( asyncIterable ) ; } describe ( 'v1.SecretManagerServiceClient' , ( ) => { it ( 'has servicePath' , ( ) => { const servicePath = secretmanagerserviceModule . v1 . SecretManagerServiceClient . servicePath ; assert ( servicePath ) ; } ) ; it ( 'has apiEndpoint' , ( ) => { const apiEndpoint = secretmanagerserviceModule . v1 . SecretManagerServiceClient . apiEndpoint ; assert ( apiEndpoint ) ; } ) ; it ( 'has port' , ( ) => { const port = secretmanagerserviceModule . v1 . SecretManagerServiceClient . port ; assert ( port ) ; assert ( typeof port === 'number' ) ; } ) ; it ( 'should create a client with no option' , ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( ) ; assert ( client ) ; } ) ; it ( 'should create a client with gRPC fallback' , ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { fallback : true , } ) ; assert ( client ) ; } ) ; it ( 'has initialize method and supports deferred initialization' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; assert . strictEqual ( client . secretManagerServiceStub , undefined ) ; await client . initialize ( ) ; assert ( client . secretManagerServiceStub ) ; } ) ; it ( 'has close method' , ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . close ( ) ; } ) ; it ( 'has getProjectId method' , async ( ) => { const fakeProjectId = 'fake-project-id' ; const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { 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 secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { 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 ( 'createSecret' , ( ) => { it ( 'invokes createSecret without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . CreateSecretRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . createSecret = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . createSecret ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes createSecret without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . CreateSecretRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . createSecret = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . createSecret ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . createSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes createSecret with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . CreateSecretRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . createSecret = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . createSecret ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . createSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'addSecretVersion' , ( ) => { it ( 'invokes addSecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AddSecretVersionRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . addSecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . addSecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . addSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes addSecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AddSecretVersionRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . addSecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . addSecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . addSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes addSecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AddSecretVersionRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . addSecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . addSecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . addSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getSecret' , ( ) => { it ( 'invokes getSecret without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . getSecret = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getSecret ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getSecret without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . getSecret = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getSecret ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getSecret with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getSecret = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getSecret ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'updateSecret' , ( ) => { it ( 'invokes updateSecret without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . UpdateSecretRequest ( ) ) ; request . secret = { } ; request . secret . name = '' ; const expectedHeaderRequestParams = 'secret.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . updateSecret = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . updateSecret ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes updateSecret without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . UpdateSecretRequest ( ) ) ; request . secret = { } ; request . secret . name = '' ; const expectedHeaderRequestParams = 'secret.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) ; client . innerApiCalls . updateSecret = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . updateSecret ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . updateSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes updateSecret with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . UpdateSecretRequest ( ) ) ; request . secret = { } ; request . secret . name = '' ; const expectedHeaderRequestParams = 'secret.name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . updateSecret = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . updateSecret ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . updateSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'deleteSecret' , ( ) => { it ( 'invokes deleteSecret without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DeleteSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteSecret = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . deleteSecret ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes deleteSecret without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DeleteSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . protobuf . Empty ( ) ) ; client . innerApiCalls . deleteSecret = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . deleteSecret ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . deleteSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes deleteSecret with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DeleteSecretRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . deleteSecret = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . deleteSecret ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . deleteSecret as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getSecretVersion' , ( ) => { it ( 'invokes getSecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . getSecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getSecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getSecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . getSecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getSecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getSecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . GetSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getSecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getSecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'accessSecretVersion' , ( ) => { it ( 'invokes accessSecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AccessSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AccessSecretVersionResponse ( ) ) ; client . innerApiCalls . accessSecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . accessSecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . accessSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes accessSecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AccessSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AccessSecretVersionResponse ( ) ) ; client . innerApiCalls . accessSecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . accessSecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . accessSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes accessSecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . AccessSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . accessSecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . accessSecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . accessSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'disableSecretVersion' , ( ) => { it ( 'invokes disableSecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DisableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . disableSecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . disableSecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . disableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes disableSecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DisableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . disableSecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . disableSecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . disableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes disableSecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DisableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . disableSecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . disableSecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . disableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'enableSecretVersion' , ( ) => { it ( 'invokes enableSecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . EnableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . enableSecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . enableSecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . enableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes enableSecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . EnableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . enableSecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . enableSecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . enableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes enableSecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . EnableSecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . enableSecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . enableSecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . enableSecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'destroySecretVersion' , ( ) => { it ( 'invokes destroySecretVersion without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DestroySecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . destroySecretVersion = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . destroySecretVersion ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . destroySecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes destroySecretVersion without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DestroySecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) ; client . innerApiCalls . destroySecretVersion = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . destroySecretVersion ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . destroySecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes destroySecretVersion with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . DestroySecretVersionRequest ( ) ) ; request . name = '' ; const expectedHeaderRequestParams = 'name=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . destroySecretVersion = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . destroySecretVersion ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . destroySecretVersion as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'setIamPolicy' , ( ) => { it ( 'invokes setIamPolicy without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . setIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes setIamPolicy without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . setIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . setIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes setIamPolicy with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . SetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . setIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . setIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . setIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'getIamPolicy' , ( ) => { it ( 'invokes getIamPolicy without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . getIamPolicy ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes getIamPolicy without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . Policy ( ) ) ; client . innerApiCalls . getIamPolicy = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . getIamPolicy ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes getIamPolicy with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . GetIamPolicyRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . getIamPolicy = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . getIamPolicy ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . getIamPolicy as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'testIamPermissions' , ( ) => { it ( 'invokes testIamPermissions without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . testIamPermissions ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes testIamPermissions without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsResponse ( ) ) ; client . innerApiCalls . testIamPermissions = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . testIamPermissions ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes testIamPermissions with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . iam . v1 . TestIamPermissionsRequest ( ) ) ; request . resource = '' ; const expectedHeaderRequestParams = 'resource=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . testIamPermissions = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . testIamPermissions ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . testIamPermissions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; } ) ; describe ( 'listSecrets' , ( ) => { it ( 'invokes listSecrets without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , ] ; client . innerApiCalls . listSecrets = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listSecrets ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listSecrets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listSecrets without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , ] ; client . innerApiCalls . listSecrets = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listSecrets ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listSecrets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listSecrets with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listSecrets = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listSecrets ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listSecrets as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listSecretsStream without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , ] ; client . descriptors . page . listSecrets . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listSecretsStream ( 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 . listSecrets . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listSecrets , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listSecrets . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listSecretsStream with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listSecrets . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listSecretsStream ( 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 . listSecrets . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listSecrets , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listSecrets . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listSecrets without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . Secret ( ) ) , ] ; client . descriptors . page . listSecrets . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listSecretsAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listSecrets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listSecrets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listSecrets with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listSecrets . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listSecretsAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listSecrets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listSecrets . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'listSecretVersions' , ( ) => { it ( 'invokes listSecretVersions without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , ] ; client . innerApiCalls . listSecretVersions = stubSimpleCall ( expectedResponse ) ; const [ response ] = await client . listSecretVersions ( request ) ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listSecretVersions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listSecretVersions without error using callback' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , ] ; client . innerApiCalls . listSecretVersions = stubSimpleCallWithCallback ( expectedResponse ) ; const promise = new Promise ( ( resolve , reject ) => { client . listSecretVersions ( request , ( err ? , result ? ) => { if ( err ) { reject ( err ) ; } else { resolve ( result ) ; } } ) ; } ) ; const response = await promise ; assert . deepStrictEqual ( response , expectedResponse ) ; assert ( ( client . innerApiCalls . listSecretVersions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions ) ) ; } ) ; it ( 'invokes listSecretVersions with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedOptions = { otherArgs : { headers : { 'x-goog-request-params' : expectedHeaderRequestParams , } , } , } ; const expectedError = new Error ( 'expected' ) ; client . innerApiCalls . listSecretVersions = stubSimpleCall ( undefined , expectedError ) ; await assert . rejects ( client . listSecretVersions ( request ) , expectedError ) ; assert ( ( client . innerApiCalls . listSecretVersions as SinonStub ) . getCall ( 0 ) . calledWith ( request , expectedOptions , undefined ) ) ; } ) ; it ( 'invokes listSecretVersionsStream without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , ] ; client . descriptors . page . listSecretVersions . createStream = stubPageStreamingCall ( expectedResponse ) ; const stream = client . listSecretVersionsStream ( 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 . listSecretVersions . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listSecretVersions , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listSecretVersions . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'invokes listSecretVersionsStream with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listSecretVersions . createStream = stubPageStreamingCall ( undefined , expectedError ) ; const stream = client . listSecretVersionsStream ( 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 . listSecretVersions . createStream as SinonStub ) . getCall ( 0 ) . calledWith ( client . innerApiCalls . listSecretVersions , request ) ) ; assert . strictEqual ( ( client . descriptors . page . listSecretVersions . createStream as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listSecretVersions without error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedResponse = [ generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . SecretVersion ( ) ) , ] ; client . descriptors . page . listSecretVersions . asyncIterate = stubAsyncIterationCall ( expectedResponse ) ; const responses = [ ] ; const iterable = client . listSecretVersionsAsync ( request ) ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } assert . deepStrictEqual ( responses , expectedResponse ) ; assert . deepStrictEqual ( ( client . descriptors . page . listSecretVersions . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listSecretVersions . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; it ( 'uses async iteration with listSecretVersions with error' , async ( ) => { const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; const request = generateSampleMessage ( new protos . google . cloud . secretmanager . v1 . ListSecretVersionsRequest ( ) ) ; request . parent = '' ; const expectedHeaderRequestParams = 'parent=' ; const expectedError = new Error ( 'expected' ) ; client . descriptors . page . listSecretVersions . asyncIterate = stubAsyncIterationCall ( undefined , expectedError ) ; const iterable = client . listSecretVersionsAsync ( request ) ; await assert . rejects ( async ( ) => { const responses = [ ] ; for await ( const resource of iterable ) { responses . push ( resource ! ) ; } } ) ; assert . deepStrictEqual ( ( client . descriptors . page . listSecretVersions . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 1 ] , request ) ; assert . strictEqual ( ( client . descriptors . page . listSecretVersions . asyncIterate as SinonStub ) . getCall ( 0 ) . args [ 2 ] . otherArgs . headers [ 'x-goog-request-params' ] , expectedHeaderRequestParams ) ; } ) ; } ) ; describe ( 'Path templates' , ( ) => { describe ( 'project' , ( ) => { const fakePath = '/rendered/path/project' ; const expectedParameters = { project : 'projectValue' , } ; const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . projectPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . projectPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'projectPath' , ( ) => { const result = client . projectPath ( 'projectValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . projectPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromProjectName' , ( ) => { const result = client . matchProjectFromProjectName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . projectPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'secret' , ( ) => { const fakePath = '/rendered/path/secret' ; const expectedParameters = { project : 'projectValue' , secret : 'secretValue' , } ; const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . secretPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . secretPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'secretPath' , ( ) => { const result = client . secretPath ( 'projectValue' , 'secretValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . secretPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromSecretName' , ( ) => { const result = client . matchProjectFromSecretName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . secretPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchSecretFromSecretName' , ( ) => { const result = client . matchSecretFromSecretName ( fakePath ) ; assert . strictEqual ( result , 'secretValue' ) ; assert ( ( client . pathTemplates . secretPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'secretVersion' , ( ) => { const fakePath = '/rendered/path/secretVersion' ; const expectedParameters = { project : 'projectValue' , secret : 'secretValue' , secret_version : 'secretVersionValue' , } ; const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . secretVersionPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . secretVersionPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'secretVersionPath' , ( ) => { const result = client . secretVersionPath ( 'projectValue' , 'secretValue' , 'secretVersionValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . secretVersionPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromSecretVersionName' , ( ) => { const result = client . matchProjectFromSecretVersionName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . secretVersionPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchSecretFromSecretVersionName' , ( ) => { const result = client . matchSecretFromSecretVersionName ( fakePath ) ; assert . strictEqual ( result , 'secretValue' ) ; assert ( ( client . pathTemplates . secretVersionPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchSecretVersionFromSecretVersionName' , ( ) => { const result = client . matchSecretVersionFromSecretVersionName ( fakePath ) ; assert . strictEqual ( result , 'secretVersionValue' ) ; assert ( ( client . pathTemplates . secretVersionPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; describe ( 'topic' , ( ) => { const fakePath = '/rendered/path/topic' ; const expectedParameters = { project : 'projectValue' , topic : 'topicValue' , } ; const client = new secretmanagerserviceModule . v1 . SecretManagerServiceClient ( { credentials : { client_email : 'bogus' , private_key : 'bogus' } , projectId : 'bogus' , } ) ; client . initialize ( ) ; client . pathTemplates . topicPathTemplate . render = sinon . stub ( ) . returns ( fakePath ) ; client . pathTemplates . topicPathTemplate . match = sinon . stub ( ) . returns ( expectedParameters ) ; it ( 'topicPath' , ( ) => { const result = client . topicPath ( 'projectValue' , 'topicValue' ) ; assert . strictEqual ( result , fakePath ) ; assert ( ( client . pathTemplates . topicPathTemplate . render as SinonStub ) . getCall ( - 1 ) . calledWith ( expectedParameters ) ) ; } ) ; it ( 'matchProjectFromTopicName' , ( ) => { const result = client . matchProjectFromTopicName ( fakePath ) ; assert . strictEqual ( result , 'projectValue' ) ; assert ( ( client . pathTemplates . topicPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; it ( 'matchTopicFromTopicName' , ( ) => { const result = client . matchTopicFromTopicName ( fakePath ) ; assert . strictEqual ( result , 'topicValue' ) ; assert ( ( client . pathTemplates . topicPathTemplate . match as SinonStub ) . getCall ( - 1 ) . calledWith ( fakePath ) ) ; } ) ; } ) ; } ) ; } ) ;