Skip to content

Commit f14bee8

Browse files
authored
Add tests for Task Protection endpoints for the case when ECS returns more than one failure (#3749)
1 parent 7565a9a commit f14bee8

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

agent/handlers/task_server_setup_test.go

+54
Original file line numberDiff line numberDiff line change
@@ -2973,6 +2973,34 @@ func TestGetTaskProtection(t *testing.T) {
29732973
},
29742974
})
29752975
})
2976+
t.Run("more than one ecs failure", func(t *testing.T) {
2977+
testTMDSRequest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
2978+
path: path,
2979+
setStateExpectations: happyStateExpectations,
2980+
setCredentialsManagerExpectations: happyCredentialsManagerExpectations,
2981+
setTaskProtectionClientFactoryExpectations: taskProtectionClientFactoryExpectations(
2982+
&ecs.GetTaskProtectionOutput{
2983+
Failures: []*ecs.Failure{
2984+
{
2985+
Arn: aws.String(taskARN),
2986+
Reason: aws.String("ecs failure 1"),
2987+
},
2988+
{
2989+
Arn: aws.String(taskARN),
2990+
Reason: aws.String("ecs failure 2"),
2991+
},
2992+
},
2993+
}, nil),
2994+
expectedStatusCode: http.StatusInternalServerError,
2995+
expectedResponseBody: agentapi.TaskProtectionResponse{
2996+
Error: &agentapi.ErrorResponse{
2997+
Arn: taskARN,
2998+
Code: ecs.ErrCodeServerException,
2999+
Message: "Unexpected error occurred",
3000+
},
3001+
},
3002+
})
3003+
})
29763004
t.Run("happy case", func(t *testing.T) {
29773005
testTMDSRequest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
29783006
path: path,
@@ -3204,6 +3232,32 @@ func TestUpdateTaskProtection(t *testing.T) {
32043232
},
32053233
},
32063234
}))
3235+
t.Run("more than on ecs failure", runTest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
3236+
requestBody: happyReqBody,
3237+
setStateExpectations: happyStateExpectations,
3238+
setCredentialsManagerExpectations: happyCredentialsManagerExpectations,
3239+
setTaskProtectionClientFactoryExpectations: taskProtectionClientFactoryExpectations(
3240+
&ecs.UpdateTaskProtectionOutput{
3241+
Failures: []*ecs.Failure{
3242+
{
3243+
Arn: aws.String(taskARN),
3244+
Reason: aws.String("ecs failure 1"),
3245+
},
3246+
{
3247+
Arn: aws.String(taskARN),
3248+
Reason: aws.String("ecs failure 2"),
3249+
},
3250+
},
3251+
}, nil),
3252+
expectedStatusCode: http.StatusInternalServerError,
3253+
expectedResponseBody: agentapi.TaskProtectionResponse{
3254+
Error: &agentapi.ErrorResponse{
3255+
Arn: taskARN,
3256+
Code: ecs.ErrCodeServerException,
3257+
Message: "Unexpected error occurred",
3258+
},
3259+
},
3260+
}))
32073261
t.Run("empty request", runTest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
32083262
requestBody: map[string]string{},
32093263
setStateExpectations: happyStateExpectations,

0 commit comments

Comments
 (0)