From 6ba6ecf59b9204d36388de07b866f157a4d13957 Mon Sep 17 00:00:00 2001 From: baude Date: Fri, 2 Feb 2018 11:02:09 -0600 Subject: Migrate Create|Commit to ginkgo Migrate create and commit bats tests to the ginkgo test suite. In doing so, some structures had to be moved to pkg/podmanstructs/podmanstructs.go so we could do better verification of test results. Signed-off-by: baude Closes: #286 Approved by: rhatdan --- test/e2e/commit_test.go | 112 ++++++++++++++++++++++++++++++++++++++++++ test/e2e/create_test.go | 57 +++++++++++++++++++++ test/e2e/libpod_suite_test.go | 45 ++++++++++++++++- test/podman_commit.bats | 97 ------------------------------------ test/podman_create.bats | 29 ----------- 5 files changed, 213 insertions(+), 127 deletions(-) create mode 100644 test/e2e/commit_test.go create mode 100644 test/e2e/create_test.go delete mode 100644 test/podman_commit.bats delete mode 100644 test/podman_create.bats (limited to 'test') diff --git a/test/e2e/commit_test.go b/test/e2e/commit_test.go new file mode 100644 index 000000000..6955b33d1 --- /dev/null +++ b/test/e2e/commit_test.go @@ -0,0 +1,112 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman commit", 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 commit container", func() { + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session := podmanTest.Podman([]string{"commit", "test1", "foobar.com/test1-image:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"}) + check.WaitWithDefaultTimeout() + data := check.InspectImageJSON() + Expect(StringInSlice("foobar.com/test1-image:latest", data.RepoTags)).To(BeTrue()) + }) + + It("podman commit container with message", func() { + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session := podmanTest.Podman([]string{"commit", "--message", "testing-commit", "test1", "foobar.com/test1-image:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"}) + check.WaitWithDefaultTimeout() + data := check.InspectImageJSON() + Expect(data.Comment).To(Equal("testing-commit")) + }) + + It("podman commit container with author", func() { + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session := podmanTest.Podman([]string{"commit", "--author", "snoopy", "test1", "foobar.com/test1-image:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"}) + check.WaitWithDefaultTimeout() + data := check.InspectImageJSON() + Expect(data.Author).To(Equal("snoopy")) + }) + + It("podman commit container with change flag", func() { + test := podmanTest.Podman([]string{"run", "--name", "test1", "-d", fedoraMinimal, "ls"}) + test.WaitWithDefaultTimeout() + Expect(test.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session := podmanTest.Podman([]string{"commit", "--change", "LABEL=image=blue", "test1", "foobar.com/test1-image:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"}) + check.WaitWithDefaultTimeout() + data := check.InspectImageJSON() + foundBlue := false + for _, i := range data.Labels { + if i == "blue" { + foundBlue = true + break + } + } + Expect(foundBlue).To(Equal(true)) + }) + + It("podman commit container with pause flag", func() { + _, ec, _ := podmanTest.RunLsContainer("test1") + Expect(ec).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + session := podmanTest.Podman([]string{"commit", "--pause=false", "test1", "foobar.com/test1-image:latest"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + + check := podmanTest.Podman([]string{"inspect", "foobar.com/test1-image:latest"}) + check.WaitWithDefaultTimeout() + Expect(check.ExitCode()).To(Equal(0)) + }) +}) diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go new file mode 100644 index 000000000..c116cea7d --- /dev/null +++ b/test/e2e/create_test.go @@ -0,0 +1,57 @@ +package integration + +import ( + "os" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Podman create", 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 create container based on a local image", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + cid := session.OutputToString() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + + check := podmanTest.Podman([]string{"inspect", "-l"}) + check.WaitWithDefaultTimeout() + data := check.InspectContainerToJSON() + Expect(data.CtrInspectData.ID).To(ContainSubstring(cid)) + }) + + It("podman create container based on a remote image", func() { + session := podmanTest.Podman([]string{"create", BB_GLIBC, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + }) + + It("podman create using short options", func() { + session := podmanTest.Podman([]string{"create", ALPINE, "ls"}) + session.WaitWithDefaultTimeout() + Expect(session.ExitCode()).To(Equal(0)) + Expect(podmanTest.NumberOfContainers()).To(Equal(1)) + }) +}) diff --git a/test/e2e/libpod_suite_test.go b/test/e2e/libpod_suite_test.go index be9be93d8..27848517f 100644 --- a/test/e2e/libpod_suite_test.go +++ b/test/e2e/libpod_suite_test.go @@ -21,6 +21,7 @@ import ( . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" "github.com/pkg/errors" + "github.com/projectatomic/libpod/pkg/inspect" ) // - CRIO_ROOT=/var/tmp/checkout PODMAN_BINARY=/usr/bin/podman CONMON_BINARY=/usr/libexec/crio/conmon PAPR=1 sh .papr.sh @@ -218,12 +219,29 @@ func (s *PodmanSession) IsJSONOutputValid() bool { var i interface{} if err := json.Unmarshal(s.Out.Contents(), &i); err != nil { fmt.Println(err) - fmt.Println(s.OutputToString()) return false } return true } +// InspectContainerToJSON takes the session output of an inspect +// container and returns json +func (s *PodmanSession) InspectContainerToJSON() inspect.ContainerData { + var i inspect.ContainerData + err := json.Unmarshal(s.Out.Contents(), &i) + Expect(err).To(BeNil()) + return i +} + +// InspectImageJSON takes the session output of an inspect +// image and returns json +func (s *PodmanSession) InspectImageJSON() inspect.ImageData { + var i inspect.ImageData + err := json.Unmarshal(s.Out.Contents(), &i) + Expect(err).To(BeNil()) + return i +} + func (s *PodmanSession) WaitWithDefaultTimeout() { s.Wait(defaultWaitTimeout) } @@ -370,3 +388,28 @@ func (p *PodmanTest) NumberOfContainersRunning() int { } return len(containers) } + +//NumberOfContainersreturns an int of how many +// containers are currently defined. +func (p *PodmanTest) NumberOfContainers() int { + var containers []string + ps := p.Podman([]string{"ps", "-aq"}) + ps.WaitWithDefaultTimeout() + Expect(ps.ExitCode()).To(Equal(0)) + for _, i := range ps.OutputToStringArray() { + if i != "" { + containers = append(containers, i) + } + } + return len(containers) +} + +// StringInSlice determines if a string is in a string slice, returns bool +func StringInSlice(s string, sl []string) bool { + for _, i := range sl { + if i == s { + return true + } + } + return false +} diff --git a/test/podman_commit.bats b/test/podman_commit.bats deleted file mode 100644 index 45c2b010e..000000000 --- a/test/podman_commit.bats +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -IMAGE="redis:alpine" - -function teardown() { - cleanup_test -} - -function setup() { - copy_images -} - -@test "podman commit default" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d --name my_ctr ${FEDORA_MINIMAL} sleep 6000 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} images | grep image-committed" - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} stop my_ctr -} - -@test "podman commit with message flag" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d --name my_ctr ${FEDORA_MINIMAL} sleep 6000 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit --message testing-commit my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} inspect image-committed | grep testing-commit" - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} stop my_ctr -} - -@test "podman commit with author flag" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d --name my_ctr ${FEDORA_MINIMAL} sleep 6000 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit --author author-name my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} inspect image-committed | grep author-name" - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} stop my_ctr -} - -@test "podman commit with change flag" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d --name my_ctr ${FEDORA_MINIMAL} sleep 6000 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit --change LABEL=image=blue my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} inspect image-committed | grep blue" - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} stop my_ctr -} - -@test "podman commit with pause flag" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d --name my_ctr ${FEDORA_MINIMAL} sleep 6000 - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit --pause=false my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} images | grep image-committed" - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} stop my_ctr -} - -@test "podman commit non-running container" { - ${PODMAN_BINARY} ${PODMAN_OPTIONS} create --name my_ctr ${FEDORA_MINIMAL} ls - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} commit my_ctr image-committed - echo "$output" - [ "$status" -eq 0 ] - run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} images | grep image-committed" - echo "$output" - [ "$status" -eq 0 ] - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rmi image-committed - echo "$output" - [ "$status" -eq 0 ] - ${PODMAN_BINARY} ${PODMAN_OPTIONS} rm my_ctr -} diff --git a/test/podman_create.bats b/test/podman_create.bats deleted file mode 100644 index d7a9cd72e..000000000 --- a/test/podman_create.bats +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bats - -load helpers - -function setup() { - copy_images -} - -function teardown() { - cleanup_test -} - -@test "create a container based on local image" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} create $BB ls - echo "$output" - [ "$status" -eq 0 ] -} - -@test "create a container based on a remote image" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} create ${BB_GLIBC} ls - echo "$output" - [ "$status" -eq 0 ] -} - -@test "ensure short options" { - run ${PODMAN_BINARY} ${PODMAN_OPTIONS} create -dt ${BB_GLIBC} ls - echo "$output" - [ "$status" -eq 0 ] -} -- cgit v1.2.3-54-g00ecf