MCPcopy
hub / github.com/containerd/containerd / TestContainerAttach

Function TestContainerAttach

integration/client/container_linux_test.go:495–589  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

493}
494
495func TestContainerAttach(t *testing.T) {
496 t.Parallel()
497
498 client, err := newClient(t, address)
499 if err != nil {
500 t.Fatal(err)
501 }
502 defer client.Close()
503
504 var (
505 image Image
506 ctx, cancel = testContext(t)
507 id = t.Name()
508 )
509 defer cancel()
510
511 image, err = client.GetImage(ctx, testImage)
512 if err != nil {
513 t.Fatal(err)
514 }
515
516 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withCat()))
517 if err != nil {
518 t.Fatal(err)
519 }
520 defer container.Delete(ctx, WithSnapshotCleanup)
521
522 expected := "hello" + newLine
523
524 direct, err := newDirectIO(ctx, false)
525 if err != nil {
526 t.Fatal(err)
527 }
528 defer direct.Delete()
529 var (
530 wg sync.WaitGroup
531 buf = bytes.NewBuffer(nil)
532 )
533 wg.Go(func() {
534 io.Copy(buf, direct.Stdout)
535 })
536
537 task, err := container.NewTask(ctx, direct.IOCreate)
538 if err != nil {
539 t.Fatal(err)
540 }
541 defer task.Delete(ctx)
542
543 status, err := task.Wait(ctx)
544 if err != nil {
545 t.Error(err)
546 }
547
548 if err := task.Start(ctx); err != nil {
549 t.Fatal(err)
550 }
551
552 if _, err := fmt.Fprint(direct.Stdin, expected); err != nil {

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
TaskMethod · 0.95
WithImageConfigFunction · 0.92
newClientFunction · 0.85
testContextFunction · 0.85
WithNewSpecFunction · 0.85
FatalMethod · 0.80
CopyMethod · 0.80
LoadContainerMethod · 0.80
withCatFunction · 0.70
newDirectIOFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…