MCPcopy
hub / github.com/containerd/containerd / TestContainerOutput

Function TestContainerOutput

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

Source from the content-addressed store, hash-verified

297}
298
299func TestContainerOutput(t *testing.T) {
300 t.Parallel()
301
302 client, err := newClient(t, address)
303 if err != nil {
304 t.Fatal(err)
305 }
306 defer client.Close()
307
308 var (
309 image Image
310 ctx, cancel = testContext(t)
311 id = t.Name()
312 expected = "kingkoye"
313 )
314 defer cancel()
315
316 image, err = client.GetImage(ctx, testImage)
317 if err != nil {
318 t.Fatal(err)
319 }
320 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withProcessArgs("echo", expected)))
321 if err != nil {
322 t.Fatal(err)
323 }
324 defer container.Delete(ctx, WithSnapshotCleanup)
325
326 stdout := bytes.NewBuffer(nil)
327 task, err := container.NewTask(ctx, cio.NewCreator(withStdout(stdout)))
328 if err != nil {
329 t.Fatal(err)
330 }
331 defer task.Delete(ctx)
332
333 statusC, err := task.Wait(ctx)
334 if err != nil {
335 t.Fatal(err)
336 }
337
338 if err := task.Start(ctx); err != nil {
339 t.Fatal(err)
340 }
341
342 status := <-statusC
343 code, _, err := status.Result()
344 if code != 0 {
345 t.Errorf("expected status 0 but received %d: %v", code, err)
346 }
347 if _, err := task.Delete(ctx); err != nil {
348 t.Fatal(err)
349 }
350
351 actual := stdout.String()
352 // echo adds a new line
353 expected = expected + newLine
354 if actual != expected {
355 t.Errorf("expected output %q but received %q", expected, actual)
356 }

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
WithImageConfigFunction · 0.92
NewCreatorFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
withStdoutFunction · 0.85
FatalMethod · 0.80
ResultMethod · 0.80
withProcessArgsFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…