-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathprovision_test.go
70 lines (59 loc) · 1.73 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
package sparta
import (
"context"
"testing"
gocf "github.com/mweagle/go-cloudformation"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
type cloudFormationProvisionTestResource struct {
gocf.CloudFormationCustomResource
ServiceToken string
TestKey interface{}
}
func customResourceTestProvider(resourceType string) gocf.ResourceProperties {
switch resourceType {
case "Custom::ProvisionTestEmpty":
{
return &cloudFormationProvisionTestResource{}
}
default:
return nil
}
}
func init() {
gocf.RegisterCustomResourceProvider(customResourceTestProvider)
}
func TestProvision(t *testing.T) {
testProvision(t, testLambdaData(), nil)
}
func templateDecorator(ctx context.Context,
serviceName string,
lambdaResourceName string,
lambdaResource gocf.LambdaFunction,
resourceMetadata map[string]interface{},
lambdaFunctionCode *gocf.LambdaFunctionCode,
buildID string,
cfTemplate *gocf.Template,
logger *logrus.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.AddResource("ProvisionTestResource", customResource)
// Add an output
cfTemplate.Outputs["OutputDecorationTest"] = &gocf.Output{
Description: "Information about the value",
Value: gocf.String("My key"),
}
return ctx, nil
}
func TestDecorateProvision(t *testing.T) {
lambdas := testLambdaData()
lambdas[0].Decorator = templateDecorator
testProvision(t, lambdas, nil)
}