-
Notifications
You must be signed in to change notification settings - Fork 0
/
unit.test.ts
47 lines (41 loc) · 1.5 KB
/
unit.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import { createRDS } from "./index";
jest.mock("@pulumi/pulumi", () => ({
...jest.requireActual("@pulumi/pulumi"),
output: jest.fn().mockImplementation((val: any) => ({
apply: async () => val,
})),
}));
describe("createRDS function", () => {
beforeEach(() => {
jest.clearAllMocks(); // Clear all mocks before each test
});
it("should create an RDS instance with correct security group ingress rules", async () => {
// Mock the output of pulumi.output to return a value that can be used with .apply()
(pulumi.output as jest.Mock).mockResolvedValue(["mock-cidr-block"]); // Mocked CIDR block
// Mock the SecurityGroup constructor
jest.spyOn(aws.ec2, "SecurityGroup").mockImplementation(() => ({
ingress: jest.fn(), // Mocking the ingress method
}) as any); // Casting to any to avoid type errors
createRDS(); // Call createRDS function
// Check that SecurityGroup constructor was called with the correct arguments
expect(aws.ec2.SecurityGroup).toHaveBeenCalledWith(
expect.any(String), // Name of the security group
{
vpcId: expect.any(String), // Mocked VPC ID
ingress: [
{
protocol: "tcp",
fromPort: 3306,
toPort: 3306,
cidrBlocks: ["mock-cidr-block"], // Mocked CIDR block
},
],
tags: {
"Owner": expect.any(String), // Mocked owner tag
},
}
);
});
});