From 3c044f9267f62b8f7f88c7395ad325df3bf420f5 Mon Sep 17 00:00:00 2001 From: baude Date: Tue, 30 Jan 2018 13:19:01 -0600 Subject: Ginkgo Tests: ps, pull, push and rm Migrate ps, pull, push, and rm from bats to ginkgo. Also, fixed a conditional issue with adding ports when an image defines the port and the user wants to override it. Signed-off-by: baude Closes: #277 Approved by: baude --- test/e2e/libpod_suite_test.go | 18 ++++ test/e2e/ps_test.go | 202 ++++++++++++++++++++++++++++++++++++++++++ test/e2e/pull_test.go | 141 +++++++++++++++++++++++++++++ test/e2e/push_test.go | 70 +++++++++++++++ test/e2e/rm_test.go | 110 +++++++++++++++++++++++ test/e2e/rmi_test.go | 10 +-- 6 files changed, 546 insertions(+), 5 deletions(-) create mode 100644 test/e2e/ps_test.go create mode 100644 test/e2e/pull_test.go create mode 100644 test/e2e/push_test.go create mode 100644 test/e2e/rm_test.go (limited to 'test/e2e') diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index c83105325..95b9def77 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -205,6 +205,13 @@ func (s *PodmanSession) OutputToString() string { return strings.Join(fields, " ") } +// OutputToStringArray returns the output as a []string +// where each array item is a line split by newline +func (s *PodmanSession) OutputToStringArray() []string { + output := fmt.Sprintf("%s", s.Out.Contents()) + return strings.Split(output, "\n") +} + // IsJSONOutputValid attempts to unmarshall the session buffer // and if successful, returns true, else false func (s *PodmanSession) IsJSONOutputValid() bool { @@ -335,3 +342,14 @@ func (p *PodmanTest) RunSleepContainer(name string) *PodmanSession { podmanArgs = append(podmanArgs, "-d", ALPINE, "sleep", "90") return p.Podman(podmanArgs) } + +//RunLsContainer runs a simple container in the background that +// simply runs ls. If the name passed != "", it will have a name +func (p *PodmanTest) RunLsContainer(name string) *PodmanSession { + var podmanArgs = []string{"run"} + if name != "" { + podmanArgs = append(podmanArgs, "--name", name) + } + podmanArgs = append(podmanArgs, "-d", ALPINE, "ls") + return p.Podman(podmanArgs) +} diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go new file mode 100644 index 000000000..690015552 --- /dev/null +++ b/test/e2e/ps_test.go @@ -0,0 +1,202 @@ +package integration + +import ( + "os" + + "fmt" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman ps", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreAllArtifacts() + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman ps no containers", func() { + session := podmanTest.Podman([]string{"ps"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman ps default", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + }) + + It("podman ps all", func() { + session := podmanTest.RunLsContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + }) + + It("podman ps size flag", func() { + session := podmanTest.RunLsContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a", "--size"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + }) + + It("podman ps quiet flag", func() { + session := podmanTest.RunLsContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + fullCid := session.OutputToString() + + result := podmanTest.Podman([]string{"ps", "-a", "-q"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + Expect(fullCid).To(ContainSubstring(result.OutputToStringArray()[0])) + }) + + It("podman ps latest flag", func() { + session := podmanTest.RunLsContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "--latest"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + }) + + It("podman ps last flag", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.RunLsContainer("test2") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.RunLsContainer("test3") + session.WaitWithDefaultTimeout() + + Expect(session.ExitCode()).To(Equal(0)) + result := podmanTest.Podman([]string{"ps", "--last", "2"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(Equal(4)) + }) + + It("podman ps no-trunc", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + fullCid := session.OutputToString() + + result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + Expect(fullCid).To(Equal(result.OutputToStringArray()[0])) + }) + + It("podman ps namespace flag", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a", "--namespace"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(len(result.OutputToStringArray())).Should(BeNumerically(">", 0)) + }) + + It("podman ps namespace flag with json format", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(result.IsJSONOutputValid()).To(BeTrue()) + }) + + It("podman ps namespace flag with go template format", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a", "--format", "\"table {{.ID}} {{.Image}} {{.Labels}}\""}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(result.IsJSONOutputValid()).To(BeTrue()) + }) + + It("podman ps ancestor filter flag", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"ps", "-a", "--filter", "ancestor=docker.io/library/alpine:latest"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman ps id filter flag", func() { + session := podmanTest.RunLsContainer("test1") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + fullCid := session.OutputToString() + + result := podmanTest.Podman([]string{"ps", "-a", "--filter", fmt.Sprintf("id=%s", fullCid)}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman ps id filter flag", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + fullCid := session.OutputToString() + + result := podmanTest.Podman([]string{"ps", "-aq", "--no-trunc", "--filter", "status=running"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + Expect(result.OutputToStringArray()[0]).To(Equal(fullCid)) + }) + + It("podman ps mutually exclusive flags", func() { + session := podmanTest.Podman([]string{"ps", "-aqs"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + + session = podmanTest.Podman([]string{"ps", "-a", "--ns", "-s"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + }) +}) diff --git a/test/e2e/pull_test.go b/test/e2e/pull_test.go new file mode 100644 index 000000000..e24d8a5a7 --- /dev/null +++ b/test/e2e/pull_test.go @@ -0,0 +1,141 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman pull", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreAllArtifacts() + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman pull from docker with tag", func() { + session := podmanTest.Podman([]string{"pull", "busybox:glibc"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", "busybox:glibc"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman pull from docker without tag", func() { + session := podmanTest.Podman([]string{"pull", "busybox"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", "busybox"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman pull from alternate registry with tag", func() { + session := podmanTest.Podman([]string{"pull", "registry.fedoraproject.org/fedora-minimal:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", "registry.fedoraproject.org/fedora-minimal:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman pull from alternate registry without tag", func() { + session := podmanTest.Podman([]string{"pull", "registry.fedoraproject.org/fedora-minimal"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", "registry.fedoraproject.org/fedora-minimal"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman pull by digest", func() { + session := podmanTest.Podman([]string{"pull", "alpine@sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", "alpine:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + It("podman pull bogus image", func() { + session := podmanTest.Podman([]string{"pull", "umohnani/get-started"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + }) + + It("podman pull from docker-archive", func() { + session := podmanTest.Podman([]string{"save", "-o", "/tmp/alp.tar", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"pull", "docker-archive:/tmp/alp.tar"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + clean := podmanTest.SystemExec("rm", []string{"/tmp/alp.tar"}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + + It("podman pull from oci-archive", func() { + session := podmanTest.Podman([]string{"save", "--format", "oci-archive", "-o", "/tmp/oci-alp.tar", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"pull", "oci-archive:/tmp/oci-alp.tar"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + clean := podmanTest.SystemExec("rm", []string{"/tmp/oci-alp.tar"}) + clean.WaitWithDefaultTimeout() + }) + + It("podman pull from local directory", func() { + setup := podmanTest.SystemExec("mkdir", []string{"-p", "/tmp/podmantestdir"}) + setup.WaitWithDefaultTimeout() + session := podmanTest.Podman([]string{"push", "alpine", "dir:/tmp/podmantestdir"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "alpine"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"pull", "dir:/tmp/podmantestdir"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + session = podmanTest.Podman([]string{"rmi", "podmantestdir"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + clean := podmanTest.SystemExec("rm", []string{"-fr", "/tmp/podmantestdir"}) + clean.WaitWithDefaultTimeout() + }) +}) diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go new file mode 100644 index 000000000..028f96424 --- /dev/null +++ b/test/e2e/push_test.go @@ -0,0 +1,70 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman push", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreAllArtifacts() + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman push to containers/storage", func() { + session := podmanTest.Podman([]string{"push", ALPINE, "containers-storage:busybox:test"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"rmi", ALPINE}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + + session = podmanTest.Podman([]string{"rmi", "busybox:test"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Not(Equal(0))) + + session = podmanTest.Podman([]string{"rmi", "-f", "busybox:test"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + }) + + // push to oci-archive, docker-archive, and dir are tested in pull_test.go + + It("podman push to containers/storage", func() { + session := podmanTest.Podman([]string{"push", "--remove-signatures", ALPINE, "dir:/tmp/busybox"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + clean := podmanTest.SystemExec("rm", []string{"-fr", "/tmp/busybox"}) + clean.WaitWithDefaultTimeout() + Expect(clean.ExitCode()).To(Equal(0)) + }) + + It("podman push to local registry", func() { + session := podmanTest.Podman([]string{"run", "-d", "-p", "5000:5000", "docker.io/library/registry:2", "/entrypoint.sh", "/etc/docker/registry/config.yml"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + push := podmanTest.Podman([]string{"push", "--tls-verify=false", "--remove-signatures", ALPINE, "localhost:5000/my-alpine"}) + push.WaitWithDefaultTimeout() + Expect(push.ExitCode()).To(Equal(0)) + }) +}) diff --git a/test/e2e/rm_test.go b/test/e2e/rm_test.go new file mode 100644 index 000000000..1ef8ee5e6 --- /dev/null +++ b/test/e2e/rm_test.go @@ -0,0 +1,110 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman rm", func() { + var ( + tempdir string + err error + podmanTest PodmanTest + ) + + BeforeEach(func() { + tempdir, err = CreateTempDirInTempDir() + if err != nil { + os.Exit(1) + } + podmanTest = PodmanCreate(tempdir) + podmanTest.RestoreAllArtifacts() + }) + + AfterEach(func() { + podmanTest.Cleanup() + + }) + + It("podman rm stopped container", func() { + session := podmanTest.RunLsContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"rm", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman rm refuse to remove a running container", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"rm", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Not(Equal(0))) + }) + + It("podman rm created container", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"rm", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman rm created container", func() { + session := podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + cid := session.OutputToString() + + result := podmanTest.Podman([]string{"rm", "-f", cid}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman rm all containers", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"rm", "-a"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) + + It("podman rm all containers with one running and short options", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + session = podmanTest.RunSleepContainer("") + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + result := podmanTest.Podman([]string{"rm", "-af"}) + result.WaitWithDefaultTimeout() + Expect(result.ExitCode()).To(Equal(0)) + }) +}) diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go index 895c812c6..04346f5ac 100644 --- a/test/e2e/rmi_test.go +++ b/test/e2e/rmi_test.go @@ -32,21 +32,21 @@ var _ = Describe("Podman rmi", func() { It("podman rmi bogus image", func() { session := podmanTest.Podman([]string{"rmi", "debian:6.0.10"}) - session.Wait() + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(125)) }) It("podman rmi with fq name", func() { session := podmanTest.Podman([]string{"rmi", image1}) - session.Wait() + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) It("podman rmi with short name", func() { session := podmanTest.Podman([]string{"rmi", "alpine"}) - session.Wait() + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) @@ -54,7 +54,7 @@ var _ = Describe("Podman rmi", func() { It("podman rmi all images", func() { podmanTest.PullImages([]string{image3}) session := podmanTest.Podman([]string{"rmi", "-a"}) - session.Wait() + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) @@ -62,7 +62,7 @@ var _ = Describe("Podman rmi", func() { It("podman rmi all images forceably with short options", func() { podmanTest.PullImages([]string{image3}) session := podmanTest.Podman([]string{"rmi", "-fa"}) - session.Wait() + session.WaitWithDefaultTimeout() Expect(session.ExitCode()).To(Equal(0)) }) -- cgit v1.2.3-54-g00ecf