diff --git a/daemon/container/container.go b/daemon/container/container.go index 349bab718d..c178fb8f33 100644 --- a/daemon/container/container.go +++ b/daemon/container/container.go @@ -143,7 +143,7 @@ type localLogCacheMeta struct { func NewBaseContainer(id, root string) *Container { return &Container{ ID: id, - State: NewState(), + State: &State{}, ExecCommands: NewExecStore(), Root: root, MountPoints: make(map[string]*volumemounts.MountPoint), diff --git a/daemon/container/state.go b/daemon/container/state.go index 02df3329b9..3825062c7f 100644 --- a/daemon/container/state.go +++ b/daemon/container/state.go @@ -78,11 +78,6 @@ func (s StateStatus) Err() error { return s.err } -// NewState creates a default state object. -func NewState() *State { - return &State{} -} - // String returns a human-readable description of the state func (s *State) String() string { if s.Running { diff --git a/daemon/container/state_test.go b/daemon/container/state_test.go index d06cc91708..9c1887f346 100644 --- a/daemon/container/state_test.go +++ b/daemon/container/state_test.go @@ -17,7 +17,7 @@ type mockTask struct { func (t *mockTask) Pid() uint32 { return t.pid } func TestStateRunStop(t *testing.T) { - s := NewState() + s := &State{} // Begin another wait with WaitConditionRemoved. It should complete // within 200 milliseconds. @@ -110,7 +110,7 @@ func TestStateRunStop(t *testing.T) { } func TestStateTimeoutWait(t *testing.T) { - s := NewState() + s := &State{} s.Lock() s.SetRunning(nil, nil, time.Now()) @@ -159,7 +159,7 @@ func TestStateTimeoutWait(t *testing.T) { // Related issue: #39352 func TestCorrectStateWaitResultAfterRestart(t *testing.T) { - s := NewState() + s := &State{} s.Lock() s.SetRunning(nil, nil, time.Now()) diff --git a/daemon/delete_test.go b/daemon/delete_test.go index 70d83181dd..21974a0544 100644 --- a/daemon/delete_test.go +++ b/daemon/delete_test.go @@ -52,8 +52,7 @@ func TestContainerDelete(t *testing.T) { doc: "restarting container", errMsg: "container is restarting: stop the container before removing or force remove", initContainer: func() *container.Container { - c := newContainerWithState(container.NewState()) - c.State.SetRunning(nil, nil, time.Now()) + c := newContainerWithState(&container.State{Running: true, StartedAt: time.Now()}) c.State.SetRestarting(&container.ExitStatus{}) return c }, @@ -82,7 +81,7 @@ func TestContainerDelete(t *testing.T) { } func TestContainerDoubleDelete(t *testing.T) { - c := newContainerWithState(container.NewState()) + c := newContainerWithState(&container.State{}) // Mark the container as having a delete in progress c.State.SetRemovalInProgress() diff --git a/daemon/inspect_test.go b/daemon/inspect_test.go index 188b76278a..924c05179b 100644 --- a/daemon/inspect_test.go +++ b/daemon/inspect_test.go @@ -13,7 +13,7 @@ func TestGetInspectData(t *testing.T) { c := &container.Container{ ID: "inspect-me", HostConfig: &containertypes.HostConfig{}, - State: container.NewState(), + State: &container.State{}, ExecCommands: container.NewExecStore(), } diff --git a/internal/testutil/daemon/daemon.go b/internal/testutil/daemon/daemon.go index 2009c26ebe..19e6a98970 100644 --- a/internal/testutil/daemon/daemon.go +++ b/internal/testutil/daemon/daemon.go @@ -1029,7 +1029,7 @@ func (d *Daemon) TamperWithContainerConfig(t testing.TB, containerID string, tam assert.NilError(t, json.Unmarshal(configBytes, &c)) assert.NilError(t, json.Unmarshal(hostConfigBytes, &c.HostConfig)) - c.State = container.NewState() + c.State = &container.State{} tamper(&c) configBytes, err = json.Marshal(&c)