Skip to content

Commit

Permalink
Expose FaultInjection status in TaskResponse (#4285)
Browse files Browse the repository at this point in the history
* Expose FIS status in TaskResponse

* Rename the new field
  • Loading branch information
xxx0624 authored Aug 16, 2024
1 parent 177dbd2 commit fd3693c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion ecs-agent/tmds/handlers/v4/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ var (
}
)

// Returns a standard agent task response
// taskResponse returns a standard agent task response
func taskResponse() *state.TaskResponse {
return &state.TaskResponse{
TaskResponse: &v2.TaskResponse{
Expand Down Expand Up @@ -175,6 +175,13 @@ func taskResponse() *state.TaskResponse {
}
}

// taskResponseWithFaultInjectionEnabled returns a standard agent task response with FaultInjection enabled
func taskResponseWithFaultInjectionEnabled() *state.TaskResponse {
taskResponse := taskResponse()
taskResponse.FaultInjectionEnabled = true
return taskResponse
}

func TestContainerMetadata(t *testing.T) {
var setup = func(t *testing.T) (*mux.Router, *gomock.Controller, *mock_state.MockAgentState,
*mock_metrics.MockEntryFactory,
Expand Down Expand Up @@ -288,6 +295,25 @@ func TestTaskMetadata(t *testing.T) {
expectedResponseBody: *expectedTaskResponse,
})
})

t.Run("happy case with FaultInjection enabled", func(t *testing.T) {
metadata := taskResponseWithFaultInjectionEnabled()
expectedTaskResponse := taskResponseWithFaultInjectionEnabled()
expectedTaskResponse.CredentialsID = "" // credentials ID not expected
expectedTaskResponse.TaskNetworkConfig = nil // TaskNetworkConfig is not expected and would be used internally
expectedTaskResponse.FaultInjectionEnabled = false // FaultInjectionEnabled is not expected and would be used internally

handler, _, agentState, _ := setup(t)
agentState.EXPECT().
GetTaskMetadata(endpointContainerID).
Return(*metadata, nil)
testTMDSRequest(t, handler, TMDSTestCase[state.TaskResponse]{
path: path,
expectedStatusCode: http.StatusOK,
expectedResponseBody: *expectedTaskResponse,
})
})

t.Run("task lookup failure", func(t *testing.T) {
handler, _, agentState, _ := setup(t)
agentState.EXPECT().
Expand Down
1 change: 1 addition & 0 deletions ecs-agent/tmds/handlers/v4/state/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TaskResponse struct {
EphemeralStorageMetrics *EphemeralStorageMetrics `json:"EphemeralStorageMetrics,omitempty"`
CredentialsID string `json:"-"`
TaskNetworkConfig *TaskNetworkConfig `json:"-"`
FaultInjectionEnabled bool `json:"-"`
}

// TaskNetworkConfig contains required network configurations for network faults injection.
Expand Down

0 comments on commit fd3693c

Please sign in to comment.