mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
api/types/container: make ContainerState a concrete type
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -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