Skip to content

Commit

Permalink
Add tests for Task Protection endpoints for the case when ECS returns…
Browse files Browse the repository at this point in the history
… more than one failure (#3749)
  • Loading branch information
amogh09 authored Jun 16, 2023
1 parent 7565a9a commit f14bee8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions agent/handlers/task_server_setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2973,6 +2973,34 @@ func TestGetTaskProtection(t *testing.T) {
},
})
})
t.Run("more than one ecs failure", func(t *testing.T) {
testTMDSRequest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
path: path,
setStateExpectations: happyStateExpectations,
setCredentialsManagerExpectations: happyCredentialsManagerExpectations,
setTaskProtectionClientFactoryExpectations: taskProtectionClientFactoryExpectations(
&ecs.GetTaskProtectionOutput{
Failures: []*ecs.Failure{
{
Arn: aws.String(taskARN),
Reason: aws.String("ecs failure 1"),
},
{
Arn: aws.String(taskARN),
Reason: aws.String("ecs failure 2"),
},
},
}, nil),
expectedStatusCode: http.StatusInternalServerError,
expectedResponseBody: agentapi.TaskProtectionResponse{
Error: &agentapi.ErrorResponse{
Arn: taskARN,
Code: ecs.ErrCodeServerException,
Message: "Unexpected error occurred",
},
},
})
})
t.Run("happy case", func(t *testing.T) {
testTMDSRequest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
path: path,
Expand Down Expand Up @@ -3204,6 +3232,32 @@ func TestUpdateTaskProtection(t *testing.T) {
},
},
}))
t.Run("more than on ecs failure", runTest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
requestBody: happyReqBody,
setStateExpectations: happyStateExpectations,
setCredentialsManagerExpectations: happyCredentialsManagerExpectations,
setTaskProtectionClientFactoryExpectations: taskProtectionClientFactoryExpectations(
&ecs.UpdateTaskProtectionOutput{
Failures: []*ecs.Failure{
{
Arn: aws.String(taskARN),
Reason: aws.String("ecs failure 1"),
},
{
Arn: aws.String(taskARN),
Reason: aws.String("ecs failure 2"),
},
},
}, nil),
expectedStatusCode: http.StatusInternalServerError,
expectedResponseBody: agentapi.TaskProtectionResponse{
Error: &agentapi.ErrorResponse{
Arn: taskARN,
Code: ecs.ErrCodeServerException,
Message: "Unexpected error occurred",
},
},
}))
t.Run("empty request", runTest(t, TMDSTestCase[agentapi.TaskProtectionResponse]{
requestBody: map[string]string{},
setStateExpectations: happyStateExpectations,
Expand Down

0 comments on commit f14bee8

Please sign in to comment.