-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathssmParametersConstruct.test.ts
More file actions
126 lines (109 loc) · 3.98 KB
/
ssmParametersConstruct.test.ts
File metadata and controls
126 lines (109 loc) · 3.98 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import {App, Stack} from "aws-cdk-lib"
import {Template} from "aws-cdk-lib/assertions"
import {
beforeAll,
describe,
expect,
test
} from "vitest"
import {SsmParametersConstruct} from "../../src/constructs/SsmParametersConstruct"
describe("SsmParametersConstruct", () => {
let template: Template
beforeAll(() => {
const app = new App()
const stack = new Stack(app, "parameterStack")
new SsmParametersConstruct(stack, "TestingParameters", {
stackName: "mock-stack",
parameters: [
{
id: "MockParam1",
nameSuffix: "MockParam1",
description: "Description for mock parameter 1",
value: "mock-value-1",
outputExportSuffix: "MockParam1Parameter",
outputDescription: "Name of the SSM parameter holding MockParam1"
},
{
id: "MockParam2",
nameSuffix: "MockParam2",
description: "Description for mock parameter 2",
value: "mock-value-2",
outputExportSuffix: "MockParam2Parameter",
outputDescription: "Name of the SSM parameter holding MockParam2"
},
{
id: "MockParam3",
nameSuffix: "MockParam3",
description: "Description for mock parameter 3",
value: "mock-value-3",
outputExportSuffix: "MockParam3Parameter",
outputDescription: "Name of the SSM parameter holding MockParam3"
}
],
readPolicyDescription: "Mock policy description",
readPolicyOutputDescription: "Mock read policy output description",
readPolicyExportSuffix: "MockGetParametersPolicy"
})
template = Template.fromStack(stack)
})
test("creates all SSM parameters", () => {
template.hasResourceProperties("AWS::SSM::Parameter", {
Name: "mock-stack-MockParam1",
Type: "String",
Value: "mock-value-1"
})
template.hasResourceProperties("AWS::SSM::Parameter", {
Name: "mock-stack-MockParam2",
Type: "String",
Value: "mock-value-2"
})
template.hasResourceProperties("AWS::SSM::Parameter", {
Name: "mock-stack-MockParam3",
Type: "String",
Value: "mock-value-3"
})
})
test("creates read policy with GetParameter actions for all parameters", () => {
const policies = template.findResources("AWS::IAM::ManagedPolicy", {
Properties: {
Description: "Mock policy description"
}
})
expect(Object.keys(policies)).toHaveLength(1)
const policy = Object.values(policies)[0] as {
Properties: {
PolicyDocument: {
Statement: Array<{
Action: Array<string>
Resource: Array<unknown>
}>
}
}
}
const statement = policy.Properties.PolicyDocument.Statement[0]
expect(statement.Action).toEqual(["ssm:GetParameter", "ssm:GetParameters"])
expect(statement.Resource).toHaveLength(3)
})
test("exports parameter names and policy ARN", () => {
const outputs = template.toJSON().Outputs as Record<string, {
Description?: string
Export?: {
Name?: string
}
}>
const exportedNames = Object.values(outputs)
.map((output) => output.Export?.Name)
.filter((name): name is string => name !== undefined)
const descriptions = Object.values(outputs)
.map((output) => output.Description)
.filter((description): description is string => description !== undefined)
expect(exportedNames).toContain("mock-stack-MockParam1Parameter")
expect(exportedNames).toContain("mock-stack-MockParam2Parameter")
expect(exportedNames).toContain("mock-stack-MockParam3Parameter")
expect(exportedNames).toContain("mock-stack-MockGetParametersPolicy")
expect(descriptions).toContain("Name of the SSM parameter holding MockParam1")
expect(descriptions).toContain("Name of the SSM parameter holding MockParam2")
expect(descriptions).toContain("Name of the SSM parameter holding MockParam3")
expect(descriptions).toContain("Mock read policy output description")
})
})