fixup! refactor(container): restart handling

This commit is contained in:
Rob Watson 2025-04-12 20:05:24 +02:00
parent a0a2e55a67
commit aba53e7cd3
3 changed files with 4 additions and 63 deletions

View File

@ -37,7 +37,6 @@ type DockerClient interface {
io.Closer
ContainerCreate(context.Context, *container.Config, *container.HostConfig, *network.NetworkingConfig, *ocispec.Platform, string) (container.CreateResponse, error)
ContainerInspect(context.Context, string) (container.InspectResponse, error)
ContainerList(context.Context, container.ListOptions) ([]container.Summary, error)
ContainerRemove(context.Context, string, container.RemoveOptions) error
ContainerStart(context.Context, string, container.StartOptions) error

View File

@ -69,10 +69,6 @@ func TestClientRunContainer(t *testing.T) {
EXPECT().
ContainerWait(mock.Anything, "123", dockercontainer.WaitConditionNextExit).
Return(containerWaitC, containerErrC)
dockerClient.
EXPECT().
ContainerInspect(mock.Anything, "123").
Return(dockercontainer.InspectResponse{ContainerJSONBase: &dockercontainer.ContainerJSONBase{State: &dockercontainer.State{Status: "exited"}}}, nil)
dockerClient.
EXPECT().
Events(mock.Anything, events.ListOptions{Filters: filters.NewArgs(filters.Arg("container", "123"), filters.Arg("type", "container"))}).
@ -98,6 +94,9 @@ func TestClientRunContainer(t *testing.T) {
Mode: 0755,
},
},
ShouldRestart: func(int64, int, time.Duration) (bool, error) {
return false, nil
},
})
done := make(chan struct{})
@ -122,7 +121,7 @@ func TestClientRunContainer(t *testing.T) {
assert.Equal(t, "unhealthy", state.HealthState)
require.NotNil(t, state.ExitCode)
assert.Equal(t, 1, *state.ExitCode)
assert.Equal(t, 1, state.RestartCount)
assert.Equal(t, 0, state.RestartCount)
<-done
}

View File

@ -138,63 +138,6 @@ func (_c *DockerClient_ContainerCreate_Call) RunAndReturn(run func(context.Conte
return _c
}
// ContainerInspect provides a mock function with given fields: _a0, _a1
func (_m *DockerClient) ContainerInspect(_a0 context.Context, _a1 string) (typescontainer.InspectResponse, error) {
ret := _m.Called(_a0, _a1)
if len(ret) == 0 {
panic("no return value specified for ContainerInspect")
}
var r0 typescontainer.InspectResponse
var r1 error
if rf, ok := ret.Get(0).(func(context.Context, string) (typescontainer.InspectResponse, error)); ok {
return rf(_a0, _a1)
}
if rf, ok := ret.Get(0).(func(context.Context, string) typescontainer.InspectResponse); ok {
r0 = rf(_a0, _a1)
} else {
r0 = ret.Get(0).(typescontainer.InspectResponse)
}
if rf, ok := ret.Get(1).(func(context.Context, string) error); ok {
r1 = rf(_a0, _a1)
} else {
r1 = ret.Error(1)
}
return r0, r1
}
// DockerClient_ContainerInspect_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ContainerInspect'
type DockerClient_ContainerInspect_Call struct {
*mock.Call
}
// ContainerInspect is a helper method to define mock.On call
// - _a0 context.Context
// - _a1 string
func (_e *DockerClient_Expecter) ContainerInspect(_a0 interface{}, _a1 interface{}) *DockerClient_ContainerInspect_Call {
return &DockerClient_ContainerInspect_Call{Call: _e.mock.On("ContainerInspect", _a0, _a1)}
}
func (_c *DockerClient_ContainerInspect_Call) Run(run func(_a0 context.Context, _a1 string)) *DockerClient_ContainerInspect_Call {
_c.Call.Run(func(args mock.Arguments) {
run(args[0].(context.Context), args[1].(string))
})
return _c
}
func (_c *DockerClient_ContainerInspect_Call) Return(_a0 typescontainer.InspectResponse, _a1 error) *DockerClient_ContainerInspect_Call {
_c.Call.Return(_a0, _a1)
return _c
}
func (_c *DockerClient_ContainerInspect_Call) RunAndReturn(run func(context.Context, string) (typescontainer.InspectResponse, error)) *DockerClient_ContainerInspect_Call {
_c.Call.Return(run)
return _c
}
// ContainerList provides a mock function with given fields: _a0, _a1
func (_m *DockerClient) ContainerList(_a0 context.Context, _a1 typescontainer.ListOptions) ([]typescontainer.Summary, error) {
ret := _m.Called(_a0, _a1)