Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose FaultInjection status in TaskResponse #4285

Merged
merged 3 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading