mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Merge pull request #51439 from thaJeztah/concrete_enums
api/types/container: make ContainerState, HealthStatus concrete types
This commit is contained in:
@@ -7,9 +7,7 @@ import (
|
||||
)
|
||||
|
||||
// HealthStatus is a string representation of the container's health.
|
||||
//
|
||||
// It currently is an alias for string, but may become a distinct type in future.
|
||||
type HealthStatus = string
|
||||
type HealthStatus string
|
||||
|
||||
// Health states
|
||||
const (
|
||||
@@ -41,7 +39,10 @@ type HealthcheckResult struct {
|
||||
}
|
||||
|
||||
var validHealths = []string{
|
||||
NoHealthcheck, Starting, Healthy, Unhealthy,
|
||||
string(NoHealthcheck),
|
||||
string(Starting),
|
||||
string(Healthy),
|
||||
string(Unhealthy),
|
||||
}
|
||||
|
||||
// ValidateHealthStatus checks if the provided string is a valid
|
||||
|
||||
@@ -19,7 +19,7 @@ func TestValidateHealthStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.health, func(t *testing.T) {
|
||||
t.Run(string(tc.health), func(t *testing.T) {
|
||||
err := ValidateHealthStatus(tc.health)
|
||||
if tc.expectedErr == "" {
|
||||
assert.NilError(t, err)
|
||||
|
||||
@@ -6,9 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// ContainerState is a string representation of the container's current state.
|
||||
//
|
||||
// It currently is an alias for string, but may become a distinct type in the future.
|
||||
type ContainerState = string
|
||||
type ContainerState string
|
||||
|
||||
const (
|
||||
StateCreated ContainerState = "created" // StateCreated indicates the container is created, but not (yet) started.
|
||||
@@ -20,8 +18,14 @@ const (
|
||||
StateDead ContainerState = "dead" // StateDead indicates that the container failed to be deleted. Containers in this state are attempted to be cleaned up when the daemon restarts.
|
||||
)
|
||||
|
||||
var validStates = []ContainerState{
|
||||
StateCreated, StateRunning, StatePaused, StateRestarting, StateRemoving, StateExited, StateDead,
|
||||
var validStates = []string{
|
||||
string(StateCreated),
|
||||
string(StateRunning),
|
||||
string(StatePaused),
|
||||
string(StateRestarting),
|
||||
string(StateRemoving),
|
||||
string(StateExited),
|
||||
string(StateDead),
|
||||
}
|
||||
|
||||
// ValidateContainerState checks if the provided string is a valid
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestValidateContainerState(t *testing.T) {
|
||||
{state: "invalid-state-string", expectedErr: `invalid value for state (invalid-state-string): must be one of created, running, paused, restarting, removing, exited, dead`},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.state, func(t *testing.T) {
|
||||
t.Run(string(tc.state), func(t *testing.T) {
|
||||
err := ValidateContainerState(tc.state)
|
||||
if tc.expectedErr == "" {
|
||||
assert.NilError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user