mirror of
https://gitea.com/gitea/act_runner.git
synced 2026-03-20 03:46:09 +08:00
refactor: migrate container changes (#91)
* refactor: migrate container changes * ignore contextcheck
This commit is contained in:
@@ -83,6 +83,16 @@ func (m *mockDockerClient) CopyToContainer(ctx context.Context, id string, path
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *mockDockerClient) ContainerKill(ctx context.Context, containerID string, signal string) error {
|
||||
args := m.Called(ctx, containerID, signal)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
func (m *mockDockerClient) ContainerStart(ctx context.Context, containerID string, options container.StartOptions) error {
|
||||
args := m.Called(ctx, containerID, options)
|
||||
return args.Error(0)
|
||||
}
|
||||
|
||||
type endlessReader struct {
|
||||
io.Reader
|
||||
}
|
||||
@@ -117,6 +127,8 @@ func TestDockerExecAbort(t *testing.T) {
|
||||
Conn: conn,
|
||||
Reader: bufio.NewReader(endlessReader{}),
|
||||
}, nil)
|
||||
client.On("ContainerKill", mock.Anything, "123", "kill").Return(nil)
|
||||
client.On("ContainerStart", mock.Anything, "123", mock.AnythingOfType("container.StartOptions")).Return(nil)
|
||||
|
||||
cr := &containerReference{
|
||||
id: "123",
|
||||
@@ -129,7 +141,7 @@ func TestDockerExecAbort(t *testing.T) {
|
||||
channel := make(chan error)
|
||||
|
||||
go func() {
|
||||
channel <- cr.exec([]string{""}, map[string]string{}, "user", "workdir")(ctx)
|
||||
channel <- cr.execExt([]string{""}, map[string]string{}, "user", "workdir")(ctx)
|
||||
}()
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
@@ -166,7 +178,7 @@ func TestDockerExecFailure(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err := cr.exec([]string{""}, map[string]string{}, "user", "workdir")(ctx)
|
||||
err := cr.execExt([]string{""}, map[string]string{}, "user", "workdir")(ctx)
|
||||
assert.Error(t, err, "exit with `FAILURE`: 1")
|
||||
|
||||
conn.AssertExpectations(t)
|
||||
|
||||
Reference in New Issue
Block a user