-
Notifications
You must be signed in to change notification settings - Fork 48
/
provision_test.go
73 lines (61 loc) · 1.92 KB
/
provision_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
package sparta
import (
"context"
"testing"
gofcloudformation "github.com/awslabs/goformation/v5/cloudformation/cloudformation"
cwCustomProvider "github.com/mweagle/Sparta/v3/aws/cloudformation/provider"
gof "github.com/awslabs/goformation/v5/cloudformation"
goflambda "github.com/awslabs/goformation/v5/cloudformation/lambda"
"github.com/pkg/errors"
"github.com/rs/zerolog"
)
type cloudFormationProvisionTestResource struct {
gofcloudformation.CustomResource
TestKey interface{}
}
func customResourceTestProvider(resourceType string) gof.Resource {
switch resourceType {
case "Custom::ProvisionTestEmpty":
{
return &cloudFormationProvisionTestResource{}
}
default:
return nil
}
}
func init() {
cwCustomProvider.RegisterCustomResourceProvider(customResourceTestProvider)
}
func TestProvision(t *testing.T) {
testProvision(t, testLambdaData(), nil)
}
func templateDecorator(ctx context.Context,
serviceName string,
lambdaResourceName string,
lambdaResource *goflambda.Function,
resourceMetadata map[string]interface{},
lambdaFunctionCode *goflambda.Function_Code,
buildID string,
cfTemplate *gof.Template,
logger *zerolog.Logger) (context.Context, error) {
// Add an empty resource
newResource, err := newCloudFormationResource("Custom::ProvisionTestEmpty", logger)
if nil != err {
return ctx, errors.Wrapf(err, "Failed to create test resource")
}
customResource := newResource.(*cloudFormationProvisionTestResource)
customResource.ServiceToken = "arn:aws:sns:us-east-1:84969EXAMPLE:CRTest"
customResource.TestKey = "Hello World"
cfTemplate.Resources["ProvisionTestResource"] = customResource
// Add an output
cfTemplate.Outputs["OutputDecorationTest"] = gof.Output{
Description: "Information about the value",
Value: "My key",
}
return ctx, nil
}
func TestDecorateProvision(t *testing.T) {
lambdas := testLambdaData()
lambdas[0].Decorator = templateDecorator
testProvision(t, lambdas, nil)
}