https://pulumi.com logo
#typescript
Title
# typescript
g

great-vr-65723

03/17/2020, 4:09 AM
Hi - I'm trying to write a unit test for a function that calls:
Copy code
aws.getCallerIdentity().accountId
I'm trying to find information on mock AWS providers for Pulumi. I found this PR, but zero additional documentation for how to use it. I also can't find much information about tests beyond this blog post that is very cursory. Anyway, does anyone have any information about how to mock the AWS provider? Spefically the
getCallerIdentity()
function?
w

white-balloon-205

03/17/2020, 5:13 AM
Mocking support was added very recently in https://github.com/pulumi/pulumi/pull/3738. Documentation and examples for mocking using the improvements in that PR are coming soon. @tall-librarian-49374 is working on some content around this. In the meantime - this gist may help? https://gist.github.com/pgavlin/8904a129d1c5e826606ca8482b6386bd#file-ec2tests-js
👍 1
g

great-vr-65723

03/23/2020, 3:56 AM
Thanks for that, the examples are useful, but I'm struggling a bit with the
call
Mock. From the type definition I see:
Copy code
* @param token: The token that indicates which function is being called. This token is of the form "package:module:function".
And I have a mock like:
Copy code
pulumi.runtime.setMocks({
    call(token: string, args: any, provider?: string): any {
        if (token === "aws:iam:getPolicyDocument") {
            return {args};
        }
    },
    newResource(type: string, name: string, inputs: any, provider?: string, id?: string): any {
        return undefined
    }
});
But I'm not sure if I'm setting the token correctly. The type definition says `
Copy code
call mocks provider-implemented function calls (e.g. aws.get_availability_zones).
But that doesn't seem to match the format in the
@param
statement.
Also, the TypeScript
Mock
requires both
call
and
newResource
to be set, even though I'm not using
newResource
for my test.
Does anyone have an example
call
Mock they can point me to, especially a TypeScript one?