Skip to content

Instantly share code, notes, and snippets.

@tenwit
Created October 18, 2022 22:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
MCVE illustrating problems testing anything that constructs a CallbackFunction mixin. Run using `node --unhandled-rejections=string node_modules/.bin/jest`
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
class CallbackFunctionWrapper extends pulumi.ComponentResource {
constructor(name: string) {
super("mcve:example:CallbackFunc", name, {});
const role = new aws.iam.Role(name, {
assumeRolePolicy: {
Version: "2012-10-17",
Statement: []
} as aws.iam.PolicyDocument
});
new aws.lambda.CallbackFunction<void, void>(name, {
role: role,
callback: async () => {}
});
}
}
describe("Wrapper", function wrapper() {
it("should run without dumping a stack to console", function mcve() {
new CallbackFunctionWrapper("mcve");
expect(true).toBe(true);
})
});
beforeAll(function setUpState() {
pulumi.runtime.setMocks({
newResource: (
args: pulumi.runtime.MockResourceArgs,
): { id: string; state: any } => {
let state = {
...args.inputs,
id: `${args.inputs.name ?? args.name}_id`,
name: args.inputs.name ?? args.name,
arn: `aws:arn:us-west-2:${args.type}:${args.name}:${args.name}_id`, // The ARN value doesn't matter. It just needs a value to prove that it has been created.
};
return {
id: state.id,
state: state,
};
},
call: (args: pulumi.runtime.MockCallArgs) => {
return args.inputs;
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment