-
Notifications
You must be signed in to change notification settings - Fork 1
/
go-cdk-go-managed-apprunner_test.go
84 lines (67 loc) · 2.5 KB
/
go-cdk-go-managed-apprunner_test.go
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
package main
import (
"go-cdk-go-managed-apprunner/cdk/input"
"testing"
"github.com/aws/aws-cdk-go/awscdk/v2"
assertions "github.com/aws/aws-cdk-go/awscdk/v2/assertions"
"github.com/aws/jsii-runtime-go"
"github.com/bradleyjkemp/cupaloy/v2"
)
func TestAppRunnerStack(t *testing.T) {
// GIVEN
app := awscdk.NewApp(nil)
appRunnerStackInputProps := input.NewAppRunnerStackInputProps()
appRunnerStackProps := &AppRunnerStackProps{
awscdk.StackProps{
Env: env(
appRunnerStackInputProps.StackEnv.Account,
appRunnerStackInputProps.StackEnv.Region,
),
},
appRunnerStackInputProps,
}
// WHEN
stack := NewAppRunnerStack(app, "AppRunnerStack", appRunnerStackProps)
// THEN
template := assertions.Template_FromStack(stack, nil)
templateJson := convertSnapshot(template.ToJSON())
t.Run("Snapshot Test", func(t *testing.T) {
cupaloy.SnapshotT(t, templateJson)
})
t.Run("CustomResourceLambda created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::Lambda::Function"), jsii.Number(1))
})
t.Run("AutoScalingConfiguration created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("Custom::AutoScalingConfiguration"), jsii.Number(1))
})
t.Run("IAMRole created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::IAM::Role"), jsii.Number(2))
})
t.Run("IAMPolicy created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::IAM::Policy"), jsii.Number(1))
})
t.Run("SecurityGroup created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::EC2::SecurityGroup"), jsii.Number(2))
})
t.Run("VpcConnector created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::AppRunner::VpcConnector"), jsii.Number(2))
})
t.Run("AppRunner Service created", func(t *testing.T) {
template.ResourceCountIs(jsii.String("AWS::AppRunner::Service"), jsii.Number(2))
})
}
func convertSnapshot(templateJson *map[string]interface{}) map[string]interface{} {
resources := (*templateJson)["Resources"].(map[string]interface{})
for key := range resources {
if valProperties, ok := resources[key].(map[string]interface{})["Properties"]; ok {
properties := valProperties.(map[string]interface{})
if valCode, ok := properties["Code"]; ok {
code := valCode.(map[string]interface{})
if _, ok := code["S3Key"]; ok {
(*templateJson)["Resources"].(map[string]interface{})[key].(map[string]interface{})["Properties"].(map[string]interface{})["Code"].(map[string]interface{})["S3Key"] = ""
}
}
}
}
return resources
}