MCPcopy Index your code
hub / github.com/containerd/containerd / TestContainerExec

Function TestContainerExec

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

Source from the content-addressed store, hash-verified

426}
427
428func TestContainerExec(t *testing.T) {
429 t.Parallel()
430
431 client, err := newClient(t, address)
432 if err != nil {
433 t.Fatal(err)
434 }
435 defer client.Close()
436
437 var (
438 image Image
439 ctx, cancel = testContext(t)
440 id = t.Name()
441 )
442 defer cancel()
443
444 image, err = client.GetImage(ctx, testImage)
445 if err != nil {
446 t.Fatal(err)
447 }
448
449 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand))
450 if err != nil {
451 t.Fatal(err)
452 }
453 defer container.Delete(ctx, WithSnapshotCleanup)
454
455 task, err := container.NewTask(ctx, empty())
456 if err != nil {
457 t.Fatal(err)
458 }
459 defer task.Delete(ctx)
460
461 finishedC, err := task.Wait(ctx)
462 if err != nil {
463 t.Fatal(err)
464 }
465
466 if err := task.Start(ctx); err != nil {
467 t.Fatal(err)
468 }
469 spec, err := container.Spec(ctx)
470 if err != nil {
471 t.Fatal(err)
472 }
473
474 // start an exec process without running the original container process info
475 processSpec := spec.Process
476 withExecExitStatus(processSpec, 6)
477 execID := t.Name() + "_exec"
478 process, err := task.Exec(ctx, execID, processSpec, empty())
479 if err != nil {
480 t.Fatal(err)
481 }
482 processStatusC, err := process.Wait(ctx)
483 if err != nil {
484 t.Fatal(err)
485 }

Callers

nothing calls this directly

Calls 15

DeleteMethod · 0.95
NewTaskMethod · 0.95
SpecMethod · 0.95
ExecMethod · 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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…