Files
podman/test/e2e/attach_test.go
Daniel J Walsh 15345ce4c3 podman create doesn't support creating detached containers
Detached containers and detach keys are only created with the podman run, i
exec, and start commands.  We do not store the detach key sequence or the
detach flags in the database, nor does Docker. The current code was ignoreing
these fields but documenting that they can be used.

Fix podman create man page and --help output to no longer indicate that
--detach and --detach-keys works.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-21 21:00:50 -04:00

121 lines
3.9 KiB
Go

package integration
import (
"os"
"syscall"
"time"
. "github.com/containers/podman/v2/test/utils"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman attach", func() {
var (
tempdir string
err error
podmanTest *PodmanTestIntegration
)
BeforeEach(func() {
tempdir, err = CreateTempDirInTempDir()
if err != nil {
os.Exit(1)
}
podmanTest = PodmanTestCreate(tempdir)
podmanTest.Setup()
podmanTest.SeedImages()
})
AfterEach(func() {
podmanTest.Cleanup()
f := CurrentGinkgoTestDescription()
processTestResult(f)
})
It("podman attach to bogus container", func() {
session := podmanTest.Podman([]string{"attach", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})
It("podman attach to non-running container", func() {
session := podmanTest.Podman([]string{"create", "--name", "test1", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"attach", "test1"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
})
It("podman container attach to non-running container", func() {
session := podmanTest.Podman([]string{"container", "create", "--name", "test1", "-i", ALPINE, "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"container", "attach", "test1"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
})
It("podman attach to multiple containers", func() {
session := podmanTest.RunTopContainer("test1")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.RunTopContainer("test2")
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"attach", "test1", "test2"})
results.WaitWithDefaultTimeout()
Expect(results.ExitCode()).To(Equal(125))
})
It("podman attach to a running container", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", ALPINE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"attach", "test"})
time.Sleep(2 * time.Second)
results.Signal(syscall.SIGTSTP)
Expect(results.OutputToString()).To(ContainSubstring("test"))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})
It("podman attach to the latest container", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test1", ALPINE, "/bin/sh", "-c", "while true; do echo test1; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
session = podmanTest.Podman([]string{"run", "-d", "--name", "test2", ALPINE, "/bin/sh", "-c", "while true; do echo test2; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
cid := "-l"
if IsRemote() {
cid = "test2"
}
results := podmanTest.Podman([]string{"attach", cid})
time.Sleep(2 * time.Second)
results.Signal(syscall.SIGTSTP)
Expect(results.OutputToString()).To(ContainSubstring("test2"))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(2))
})
It("podman attach to a container with --sig-proxy set to false", func() {
session := podmanTest.Podman([]string{"run", "-d", "--name", "test", ALPINE, "/bin/sh", "-c", "while true; do echo test; sleep 1; done"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
results := podmanTest.Podman([]string{"attach", "--sig-proxy=false", "test"})
time.Sleep(2 * time.Second)
results.Signal(syscall.SIGTERM)
results.WaitWithDefaultTimeout()
Expect(results.OutputToString()).To(ContainSubstring("test"))
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1))
})
})