-
-
Notifications
You must be signed in to change notification settings - Fork 89
/
middleware_test.go
52 lines (48 loc) · 1.52 KB
/
middleware_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
package ecspresso_test
import (
"context"
"fmt"
"strings"
"github.com/aws/aws-sdk-go-v2/service/ecs"
"github.com/aws/aws-sdk-go-v2/service/ecs/types"
"github.com/aws/smithy-go/middleware"
smithyhttp "github.com/aws/smithy-go/transport/http"
)
var middlewareResults = map[string]func(string) any{
"DescribeServices": func(family string) any {
return &ecs.DescribeServicesOutput{
Services: []types.Service{
{
TaskDefinition: ptr(fmt.Sprintf("arn:aws:ecs:ap-northeast-1:123456789012:task-definition/%s:39", family)),
},
},
}
},
"ListTaskDefinitions": func(family string) any {
td := func(rev int) string {
return fmt.Sprintf("arn:aws:ecs:ap-northeast-1:123456789012:task-definition/%s:%d", family, rev)
}
return &ecs.ListTaskDefinitionsOutput{
TaskDefinitionArns: []string{
td(45), td(44), td(43), td(42), td(41), td(40), td(39), td(38), td(37), td(36),
},
}
},
}
func SDKTestingMiddleware(family string) func(*middleware.Stack) error {
return func(stack *middleware.Stack) error {
return stack.Finalize.Add(
middleware.FinalizeMiddlewareFunc(
"test",
func(ctx context.Context, in middleware.FinalizeInput, handler middleware.FinalizeHandler) (middleware.FinalizeOutput, middleware.Metadata, error) {
req := in.Request.(*smithyhttp.Request)
target := strings.SplitN(req.Header.Get("X-Amz-Target"), ".", 2)[1]
return middleware.FinalizeOutput{
Result: middlewareResults[target](family),
}, middleware.Metadata{}, nil
},
),
middleware.Before,
)
}
}