mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
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 <bbaude@redhat.com> Closes: #286 Approved by: rhatdan
This commit is contained in:
112
test/e2e/commit_test.go
Normal file
112
test/e2e/commit_test.go
Normal file
@ -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))
|
||||
})
|
||||
})
|
57
test/e2e/create_test.go
Normal file
57
test/e2e/create_test.go
Normal file
@ -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))
|
||||
})
|
||||
})
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
@ -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 ]
|
||||
}
|
Reference in New Issue
Block a user