Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh09 authored May 8, 2024
2 parents bb73261 + 13bd226 commit c9f1baf
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 71 deletions.

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

17 changes: 2 additions & 15 deletions ecs-agent/api/container/status/containerstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ func (cs *ContainerStatus) ShouldReportToBackend(steadyStateStatus ContainerStat

// BackendStatus maps the internal container status in the agent to that in the
// backend
//
// Deprecated: Use BackendStatusString instead
func (cs *ContainerStatus) BackendStatus(steadyStateStatus ContainerStatus) ContainerStatus {
if *cs == steadyStateStatus {
return ContainerRunning
Expand All @@ -120,20 +118,9 @@ func (cs *ContainerStatus) BackendStatus(steadyStateStatus ContainerStatus) Cont

// BackendStatusString maps the internal container status in Agent to a backend recognized
// status string.
//
// Container steady state can be provided as an option. If provided, it will be used to
// determine if the backend status is "RUNNING". If not provided, then ContainerRunning is
// used as the default steady state.
func (cs ContainerStatus) BackendStatusString(steadyStateStatusPtr *ContainerStatus) string {
var steadyState ContainerStatus
if steadyStateStatusPtr != nil {
steadyState = *steadyStateStatusPtr
} else {
steadyState = ContainerRunning
}

func (cs ContainerStatus) BackendStatusString() string {
switch cs {
case steadyState:
case ContainerRunning:
return "RUNNING"
case ContainerStopped:
return "STOPPED"
Expand Down
42 changes: 1 addition & 41 deletions ecs-agent/api/container/status/containerstatus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,47 +340,7 @@ func TestContainerBackendStatusStringDefaultSteadyState(t *testing.T) {
}
for _, tc := range tcs {
t.Run(fmt.Sprintf("%d", tc.status), func(t *testing.T) {
assert.Equal(t, tc.expected, tc.status.BackendStatusString(nil))
assert.Equal(t, tc.expected, tc.status.BackendStatusString())
})
}
}

// Tests for BackendStatusString method when a steady state is provided.
func TestBackendStatusSteadyStateProvided(t *testing.T) {
containerRunning := ContainerRunning
containerResourcesProvisioned := ContainerResourcesProvisioned

// Test states that should map to PENDING regardless of steady state
pendingStates := []ContainerStatus{
ContainerStatusNone, ContainerManifestPulled, ContainerPulled,
ContainerCreated, ContainerZombie,
}
for _, tc := range pendingStates {
t.Run(fmt.Sprintf("pending - %d", tc), func(t *testing.T) {
assert.Equal(t, "PENDING", tc.BackendStatusString(&containerRunning))
assert.Equal(t, "PENDING", tc.BackendStatusString(&containerResourcesProvisioned))
})
}

// Test that ContainerStopped maps to STOPPED regardless of steady state
t.Run("ContainerStopped maps to STOPPED", func(t *testing.T) {
assert.Equal(t, "STOPPED", ContainerStopped.BackendStatusString(&containerRunning))
assert.Equal(t, "STOPPED", ContainerStopped.BackendStatusString(&containerResourcesProvisioned))
})

// Test that steady state maps to RUNNING
t.Run("ContainerRunning maps to RUNNING when steady state is ContainerRunning", func(t *testing.T) {
assert.Equal(t, "RUNNING", ContainerRunning.BackendStatusString(&containerRunning))
})
t.Run("ContainerResourcesProvisioned maps to RUNNING when steady state is ContainerResourcesProvisioned", func(t *testing.T) {
assert.Equal(t, "RUNNING", ContainerResourcesProvisioned.BackendStatusString(&containerResourcesProvisioned))
})

// Test that non-steady non-STOPPED state maps to PENDING
t.Run("ContainerRunning maps to PENDING when steady state is ContainerResourcesProvisioned", func(t *testing.T) {
assert.Equal(t, "PENDING", ContainerRunning.BackendStatusString(&containerResourcesProvisioned))
})
t.Run("ContainerResourcesProvisioned maps to PENDING when steady state is ContainerRunning", func(t *testing.T) {
assert.Equal(t, "PENDING", ContainerResourcesProvisioned.BackendStatusString(&containerRunning))
})
}

0 comments on commit c9f1baf

Please sign in to comment.