MCPcopy
hub / github.com/containerd/containerd / TestContainerStart

Function TestContainerStart

integration/client/container_test.go:108–173  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

106}
107
108func TestContainerStart(t *testing.T) {
109 t.Parallel()
110
111 client, err := newClient(t, address)
112 if err != nil {
113 t.Fatal(err)
114 }
115 defer client.Close()
116
117 var (
118 image Image
119 ctx, cancel = testContext(t)
120 id = t.Name()
121 )
122 defer cancel()
123
124 image, err = client.GetImage(ctx, testImage)
125 if err != nil {
126 t.Fatal(err)
127 }
128 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withExitStatus(7)))
129 if err != nil {
130 t.Fatal(err)
131 }
132 defer container.Delete(ctx, WithSnapshotCleanup)
133
134 task, err := container.NewTask(ctx, empty())
135 if err != nil {
136 t.Fatal(err)
137 }
138 defer task.Delete(ctx)
139
140 statusC, err := task.Wait(ctx)
141 if err != nil {
142 t.Fatal(err)
143 }
144
145 if runtime.GOOS != "windows" {
146 // task.Pid not implemented on Windows
147 if pid := task.Pid(); pid < 1 {
148 t.Errorf("invalid task pid %d", pid)
149 }
150 }
151
152 if err := task.Start(ctx); err != nil {
153 t.Error(err)
154 task.Delete(ctx)
155 return
156 }
157 status := <-statusC
158 code, _, err := status.Result()
159 if err != nil {
160 t.Fatal(err)
161 }
162 if code != 7 {
163 t.Errorf("expected status 7 from wait but received %d", code)
164 }
165

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
WithImageConfigFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
emptyFunction · 0.85
FatalMethod · 0.80
ResultMethod · 0.80
ExitCodeMethod · 0.80
withExitStatusFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…