...
1
2
3 package main
4
5 import (
6 "context"
7 "time"
8
9 "github.com/containerd/containerd/runtime/v2/task"
10 )
11
12
13
14 func newTestShimExec(tid, id string, pid int) *testShimExec {
15 return &testShimExec{
16 tid: tid,
17 id: id,
18 pid: pid,
19 state: shimExecStateCreated,
20 }
21 }
22
23 var _ = (shimExec)(&testShimExec{})
24
25 type testShimExec struct {
26 tid string
27 id string
28 pid int
29 status uint32
30 at time.Time
31
32 state shimExecState
33 }
34
35 func (tse *testShimExec) ID() string {
36 return tse.id
37 }
38 func (tse *testShimExec) Pid() int {
39 return tse.pid
40 }
41 func (tse *testShimExec) State() shimExecState {
42 return tse.state
43 }
44 func (tse *testShimExec) Status() *task.StateResponse {
45 return &task.StateResponse{
46 ID: tse.tid,
47 ExecID: tse.id,
48 Pid: uint32(tse.pid),
49 ExitStatus: tse.status,
50 ExitedAt: tse.at,
51 }
52 }
53 func (tse *testShimExec) Start(ctx context.Context) error {
54 tse.state = shimExecStateRunning
55 tse.status = 255
56 return nil
57 }
58 func (tse *testShimExec) Kill(ctx context.Context, signal uint32) error {
59 tse.state = shimExecStateExited
60 tse.status = 0
61 tse.at = time.Now()
62 return nil
63 }
64 func (tse *testShimExec) ResizePty(ctx context.Context, width, height uint32) error {
65 return nil
66 }
67 func (tse *testShimExec) CloseIO(ctx context.Context, stdin bool) error {
68 return nil
69 }
70 func (tse *testShimExec) Wait() *task.StateResponse {
71 return tse.Status()
72 }
73 func (tse *testShimExec) ForceExit(ctx context.Context, status int) {
74 if tse.state != shimExecStateExited {
75 tse.state = shimExecStateExited
76 tse.status = 1
77 tse.at = time.Now()
78 }
79 }
80
View as plain text