Skip to content

Commit be6440c

Browse files
committed
fix imds unit tests
1 parent 59ad5e3 commit be6440c

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

Diff for: feature/ec2/imds/api_op_GetToken.go

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func addGetTokenMiddleware(stack *middleware.Stack, options Options) error {
4949
err := addRequestMiddleware(stack,
5050
options,
5151
"PUT",
52+
"GetToken",
5253
buildGetTokenPath,
5354
buildGetTokenOutput)
5455
if err != nil {

Diff for: feature/ec2/imds/request_middleware.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@ func addAPIRequestMiddleware(stack *middleware.Stack,
2121
getPath func(interface{}) (string, error),
2222
getOutput func(*smithyhttp.Response) (interface{}, error),
2323
) (err error) {
24-
if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil {
25-
return fmt.Errorf("add protocol finalizers: %v", err)
26-
}
27-
28-
err = addRequestMiddleware(stack, options, "GET", getPath, getOutput)
24+
err = addRequestMiddleware(stack, options, "GET", operation, getPath, getOutput)
2925
if err != nil {
3026
return err
3127
}
@@ -49,6 +45,7 @@ func addAPIRequestMiddleware(stack *middleware.Stack,
4945
func addRequestMiddleware(stack *middleware.Stack,
5046
options Options,
5147
method string,
48+
operation string,
5249
getPath func(interface{}) (string, error),
5350
getOutput func(*smithyhttp.Response) (interface{}, error),
5451
) (err error) {
@@ -106,6 +103,10 @@ func addRequestMiddleware(stack *middleware.Stack,
106103
return err
107104
}
108105

106+
if err := addProtocolFinalizerMiddlewares(stack, options, operation); err != nil {
107+
return fmt.Errorf("add protocol finalizers: %v", err)
108+
}
109+
109110
// Retry support
110111
return retry.AddRetryMiddlewares(stack, retry.AddRetryMiddlewaresOptions{
111112
Retryer: options.Retryer,

Diff for: feature/ec2/imds/request_middleware_test.go

+11-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestAddRequestMiddleware(t *testing.T) {
3333
"api request": {
3434
AddMiddleware: func(stack *middleware.Stack, options Options) error {
3535
return addAPIRequestMiddleware(stack, options,
36-
"TestRequest"
36+
"TestRequest",
3737
func(interface{}) (string, error) {
3838
return "/mockPath", nil
3939
},
@@ -54,9 +54,13 @@ func TestAddRequestMiddleware(t *testing.T) {
5454
"UserAgent",
5555
},
5656
ExpectFinalize: []string{
57+
"ResolveAuthScheme",
58+
"GetIdentity",
59+
"ResolveEndpointV2",
5760
"Retry",
5861
"APITokenProvider",
5962
"RetryMetricsHeader",
63+
"Signing",
6064
},
6165
ExpectDeserialize: []string{
6266
"APITokenProvider",
@@ -67,7 +71,7 @@ func TestAddRequestMiddleware(t *testing.T) {
6771

6872
"base request": {
6973
AddMiddleware: func(stack *middleware.Stack, options Options) error {
70-
return addRequestMiddleware(stack, options, "POST",
74+
return addRequestMiddleware(stack, options, "POST", "TestRequest",
7175
func(interface{}) (string, error) {
7276
return "/mockPath", nil
7377
},
@@ -88,8 +92,12 @@ func TestAddRequestMiddleware(t *testing.T) {
8892
"UserAgent",
8993
},
9094
ExpectFinalize: []string{
95+
"ResolveAuthScheme",
96+
"GetIdentity",
97+
"ResolveEndpointV2",
9198
"Retry",
9299
"RetryMetricsHeader",
100+
"Signing",
93101
},
94102
ExpectDeserialize: []string{
95103
"OperationDeserializer",
@@ -591,7 +599,7 @@ func TestRequestGetToken(t *testing.T) {
591599
func(stack *middleware.Stack, options Options) error {
592600
return addAPIRequestMiddleware(stack,
593601
client.options.Copy(),
594-
"TestRequest"
602+
"TestRequest",
595603
func(interface{}) (string, error) {
596604
return "/latest/foo", nil
597605
},

0 commit comments

Comments
 (0)