MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestIssue3568

Function TestIssue3568

cmd/nerdctl/container/container_run_linux_test.go:584–628  ·  view source on GitHub ↗

TestIssue3568 tests https://github.com/containerd/nerdctl/issues/3568

(t *testing.T)

Source from the content-addressed store, hash-verified

582
583// TestIssue3568 tests https://github.com/containerd/nerdctl/issues/3568
584func TestIssue3568(t *testing.T) {
585 testCase := nerdtest.Setup()
586
587 testCase.Description = "Issue #3568 - Detaching from a container started by using --rm option causes the container to be deleted."
588
589 testCase.Cleanup = func(data test.Data, helpers test.Helpers) {
590 helpers.Anyhow("rm", "-f", data.Identifier())
591 }
592
593 testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand {
594 // Run interactively and detach
595 cmd := helpers.Command("run", "--rm", "-it", "--detach-keys=ctrl-a,ctrl-b", "--name", data.Identifier(), testutil.CommonImage)
596 cmd.WithPseudoTTY()
597 cmd.Feed(strings.NewReader("echo mark${NON}mark\n"))
598 cmd.WithFeeder(func() io.Reader {
599 // Because of the way we proxy stdin, we have to wait here, otherwise we detach before
600 // the rest of the input ever reaches the container
601 // Note that this only concerns nerdctl, as docker seems to behave ok LOCALLY.
602 // But then, it fails for docker as well ON THE CI. It is unclear why at this point.
603 // Arbitrary time pauses would not work: what matters is that the container has started.
604 // if !nerdtest.IsDocker() {
605 nerdtest.EnsureContainerStarted(helpers, data.Identifier())
606 // }
607 // ctrl+a and ctrl+b (see https://en.wikipedia.org/wiki/C0_and_C1_control_codes)
608 return bytes.NewReader([]byte{1, 2})
609 })
610
611 return cmd
612 }
613
614 testCase.Expected = func(data test.Data, helpers test.Helpers) *test.Expected {
615 return &test.Expected{
616 ExitCode: 0,
617 Errors: []error{errors.New("detach keys")},
618 Output: expect.All(
619 expect.Contains("markmark"),
620 func(stdout string, t tig.T) {
621 assert.Assert(t, strings.Contains(helpers.Capture("inspect", "--format", "json", data.Identifier()), "\"Running\":true"))
622 },
623 ),
624 }
625 }
626
627 testCase.Run(t)
628}
629
630// TestPortBindingWithCustomHost tests https://github.com/containerd/nerdctl/issues/3539
631func TestPortBindingWithCustomHost(t *testing.T) {

Callers

nothing calls this directly

Calls 11

SetupFunction · 0.92
EnsureContainerStartedFunction · 0.92
AssertMethod · 0.80
AnyhowMethod · 0.65
IdentifierMethod · 0.65
CommandMethod · 0.65
WithPseudoTTYMethod · 0.65
FeedMethod · 0.65
WithFeederMethod · 0.65
CaptureMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…