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

Function TestDeleteRunningContainer

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

Source from the content-addressed store, hash-verified

756}
757
758func TestDeleteRunningContainer(t *testing.T) {
759 t.Parallel()
760
761 client, err := newClient(t, address)
762 if err != nil {
763 t.Fatal(err)
764 }
765 defer client.Close()
766
767 var (
768 image Image
769 ctx, cancel = testContext(t)
770 id = t.Name()
771 )
772 defer cancel()
773
774 image, err = client.GetImage(ctx, testImage)
775 if err != nil {
776 t.Fatal(err)
777 }
778
779 container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), longCommand))
780 if err != nil {
781 t.Fatal(err)
782 }
783 defer container.Delete(ctx, WithSnapshotCleanup)
784
785 task, err := container.NewTask(ctx, empty())
786 if err != nil {
787 t.Fatal(err)
788 }
789 defer task.Delete(ctx)
790
791 statusC, err := task.Wait(ctx)
792 if err != nil {
793 t.Fatal(err)
794 }
795
796 if err := task.Start(ctx); err != nil {
797 t.Fatal(err)
798 }
799
800 err = container.Delete(ctx, WithSnapshotCleanup)
801 if err == nil {
802 t.Error("delete did not error with running task")
803 }
804 if !errdefs.IsFailedPrecondition(err) {
805 t.Errorf("expected error %q but received %q", errdefs.ErrFailedPrecondition, err)
806 }
807 if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
808 t.Fatal(err)
809 }
810 <-statusC
811}
812
813func TestContainerKill(t *testing.T) {
814 t.Parallel()

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
CloseMethod · 0.65
NameMethod · 0.65
GetImageMethod · 0.65
NewContainerMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…