Skip to content

Commit 3340980

Browse files
authored
Remove test endpoint (#172)
1 parent a151b23 commit 3340980

File tree

4 files changed

+3
-146
lines changed

4 files changed

+3
-146
lines changed

cfn/cfn.go

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,8 @@ func Start(h Handler) {
6969
}
7070
}()
7171

72-
// MODE is an environment variable that is set ONLY
73-
// when contract test are performed.
74-
mode, _ := os.LookupEnv("MODE")
75-
76-
if mode == "Test" {
77-
log.Printf("Handler starting in test mode")
78-
lambda.Start(makeTestEventFunc(h))
79-
} else {
80-
log.Printf("Handler starting")
81-
lambda.Start(makeEventFunc(h))
82-
}
72+
log.Printf("Handler starting")
73+
lambda.Start(makeEventFunc(h))
8374

8475
log.Printf("Handler finished")
8576
}
@@ -90,10 +81,6 @@ type tags map[string]string
9081
// eventFunc is the function signature required to execute an event from the Lambda SDK
9182
type eventFunc func(ctx context.Context, event *event) (response, error)
9283

93-
// testEventFunc is the function signature required to execute an event from the Lambda SDK
94-
// and is only used in contract testing
95-
type testEventFunc func(ctx context.Context, event *testEvent) (handler.ProgressEvent, error)
96-
9784
// handlerFunc is the signature required for all actions
9885
type handlerFunc func(request handler.Request) handler.ProgressEvent
9986

@@ -189,34 +176,6 @@ func router(a string, h Handler) (handlerFunc, error) {
189176
}
190177
}
191178

192-
// MakeTestEventFunc is the entry point that allows the CLI's
193-
// contract testing framework to invoke the resource's CRUDL handlers.
194-
func makeTestEventFunc(h Handler) testEventFunc {
195-
return func(ctx context.Context, event *testEvent) (handler.ProgressEvent, error) {
196-
handlerFn, err := router(event.Action, h)
197-
if err != nil {
198-
return handler.NewFailedEvent(err), err
199-
}
200-
rctx := handler.RequestContext{
201-
Region: event.Request.Region,
202-
AccountID: event.Request.AWSAccountID,
203-
StackTags: event.Request.DesiredResourceTags,
204-
SystemTags: event.Request.SystemTags,
205-
NextToken: event.Request.NextToken,
206-
}
207-
request := handler.NewRequest(
208-
event.Request.LogicalResourceIdentifier,
209-
event.CallbackContext,
210-
rctx,
211-
credentials.SessionFromCredentialsProvider(&event.Credentials),
212-
event.Request.PreviousResourceState,
213-
event.Request.DesiredResourceState,
214-
)
215-
progEvt := handlerFn(request)
216-
return progEvt, nil
217-
}
218-
}
219-
220179
// Invoke handles the invocation of the handerFn.
221180
func invoke(handlerFn handlerFunc, request handler.Request, metricsPublisher *metrics.Publisher, action string) handler.ProgressEvent {
222181

cfn/cfn_test.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -142,91 +142,6 @@ func loadEvent(path string, evt *event) *event {
142142
return evt
143143
}
144144

145-
func TestMakeTestEventFunc(t *testing.T) {
146-
start := time.Now()
147-
future := start.Add(time.Minute * 15)
148-
149-
tc, cancel := context.WithDeadline(context.Background(), future)
150-
151-
defer cancel()
152-
153-
lc := lambdacontext.NewContext(tc, &lambdacontext.LambdaContext{})
154-
155-
f1 := func(callback map[string]interface{}, s *session.Session) handler.ProgressEvent {
156-
response := handler.ProgressEvent{
157-
OperationStatus: handler.Success,
158-
Message: "Create complete",
159-
}
160-
return response
161-
}
162-
163-
type args struct {
164-
h Handler
165-
ctx context.Context
166-
event *testEvent
167-
}
168-
tests := []struct {
169-
name string
170-
args args
171-
want handler.ProgressEvent
172-
wantErr bool
173-
}{
174-
{"Test simple CREATE", args{&MockHandler{f1}, lc, loadTestEvent("test.create.json", &testEvent{})}, handler.ProgressEvent{
175-
OperationStatus: handler.Success,
176-
Message: "Create complete",
177-
}, false},
178-
{"Test simple READ", args{&MockHandler{f1}, lc, loadTestEvent("test.read.json", &testEvent{})}, handler.ProgressEvent{
179-
OperationStatus: handler.Success,
180-
Message: "Create complete",
181-
}, false},
182-
{"Test simple DELETE", args{&MockHandler{f1}, lc, loadTestEvent("test.delete.json", &testEvent{})}, handler.ProgressEvent{
183-
OperationStatus: handler.Success,
184-
Message: "Create complete",
185-
}, false},
186-
{"Test simple INVALID", args{&MockHandler{f1}, lc, loadTestEvent("test.INVALID.json", &testEvent{})}, handler.ProgressEvent{
187-
OperationStatus: handler.Failed,
188-
Message: "InvalidRequest: No action/invalid action specified",
189-
}, true},
190-
}
191-
for _, tt := range tests {
192-
t.Run(tt.name, func(t *testing.T) {
193-
f := makeTestEventFunc(tt.args.h)
194-
got, err := f(tt.args.ctx, tt.args.event)
195-
196-
if (err != nil) != tt.wantErr {
197-
t.Errorf("makeEventFunc() = %v, wantErr %v", err, tt.wantErr)
198-
return
199-
}
200-
201-
switch tt.wantErr {
202-
case true:
203-
if tt.want.OperationStatus != got.OperationStatus {
204-
t.Errorf("response = %v; want %v", got.OperationStatus, tt.want.OperationStatus)
205-
}
206-
207-
case false:
208-
if !reflect.DeepEqual(tt.want, got) {
209-
t.Errorf("response = %v; want %v", got, tt.want)
210-
}
211-
212-
}
213-
})
214-
}
215-
}
216-
217-
//loadEvent is a helper function that unmarshal the event from a file.
218-
func loadTestEvent(path string, evt *testEvent) *testEvent {
219-
validevent, err := openFixture(path)
220-
if err != nil {
221-
log.Fatalf("Unable to read fixture: %v", err)
222-
}
223-
224-
if err := json.Unmarshal(validevent, evt); err != nil {
225-
log.Fatalf("Marshaling error with event: %v", err)
226-
}
227-
return evt
228-
}
229-
230145
func TestMakeEventFuncModel(t *testing.T) {
231146
start := time.Now()
232147
future := start.Add(time.Minute * 15)

cfn/event.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type event struct {
1616
BearerToken string `json:"bearerToken" validate:"nonzero"`
1717
Region string `json:"region" validate:"nonzero"`
1818
Action string `json:"action"`
19-
ResourceType string `json:"resourceType" validate:"nonzero"`
19+
ResourceType string `json:"resourceType"`
2020
ResourceTypeVersion encoding.Float `json:"resourceTypeVersion"`
2121
CallbackContext map[string]interface{} `json:"callbackContext,omitempty"`
2222
RequestData requestData `json:"requestData"`
@@ -48,15 +48,6 @@ func validateEvent(event *event) error {
4848
return nil
4949
}
5050

51-
// testEvent base structure, it will be internal to the RPDK.
52-
type testEvent struct {
53-
Action string `json:"action"`
54-
Credentials credentials.CloudFormationCredentialsProvider `json:"credentials"`
55-
CallbackContext map[string]interface{} `json:"callbackContext"`
56-
57-
Request resourceHandlerRequest
58-
}
59-
6051
// resourceHandlerRequest is internal to the RPDK. It contains a number of fields that are for
6152
// internal contract testing use only.
6253
type resourceHandlerRequest struct {

cfn/metrics/noop_publisher.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package metrics
22

33
import (
44
"log"
5-
"strings"
65

76
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/logging"
87
"github.com/aws/aws-sdk-go/service/cloudwatch"
@@ -21,13 +20,6 @@ type noopCloudWatchClient struct {
2120
}
2221

2322
func (n *noopCloudWatchClient) PutMetricData(input *cloudwatch.PutMetricDataInput) (*cloudwatch.PutMetricDataOutput, error) {
24-
datum := []string{}
25-
for _, v := range input.MetricData {
26-
datum = append(datum, v.GoString())
27-
}
28-
29-
n.logger.Printf("Namespace: %s, Datums: %s", *input.Namespace, strings.Join(datum, " :: "))
30-
3123
// out implementation doesn't care about the response
3224
return nil, nil
3325
}

0 commit comments

Comments
 (0)