api/types/container: make ContainerState a concrete type

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-11-07 18:18:25 +01:00
parent 69c4524355
commit 1fd87e9fdf
13 changed files with 43 additions and 31 deletions

View File

@@ -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

View File

@@ -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)