aspiringCoder
aspiringCoder

Reputation: 415

Mocking specific invocation of Lambda Invoke especially when chaining invocations

So I was wondering - been using the aws-sdk-mock library for Node / Jasmine.

This particular library allows you to mock the service method invocations. However this appears to be a problem when attempting to mock a method called more than once, but fed different parameters (thus invoking a different lambda).

Aws.mock('lambda', 'invoke', function(params, callback){
callback(null, {})
}

This will mock every call to invoke, which really isn't flexible, what I think would be useful would be to see if the params passed to it contained a specific value.

Now I would not be tied to the AWS.mock framework I don't believe, so if anyone has any pointers how to handle this, it would be great. See the invocation flow below.

Custom function (called from test) -> custom function (calling the invoke)

Upvotes: 2

Views: 2815

Answers (1)

rocketlobster
rocketlobster

Reputation: 720

I found the solution to this to be checking the parameters of the lambda being mocked. For example if you have a lambda named lambdaOne and a lambda named lambdaTwo, your mock would look like this:

Aws.mock('lambda', 'invoke', function(params, callback){
    if (params.FunctioName === 'lambdaOne'){
        callback(null, lambdaOneResponse)
    }
    else if (params.FunctioName === 'lambdaTwo')
        callback(null, lambdaTwoResponse) 
}

I hope this helps!

Upvotes: 1

Related Questions