Migrate diff, exec, export, and history to ginkgo

Migrate the diff, exec, export, and history bats tests to
the ginkgo test suite.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #287
Approved by: baude
This commit is contained in:
baude
2018-02-02 19:05:23 -06:00
committed by Atomic Bot
parent 1ac11dcf84
commit 3609b82fe6
13 changed files with 366 additions and 242 deletions

View File

@ -194,7 +194,10 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man
.install.md2man: .gopathok
if [ ! -x "$(GOPATH)/bin/go-md2man" ]; then \
go get -u github.com/cpuguy83/go-md2man; \
go get -d github.com/cpuguy83/go-md2man; \
cd $(GOPATH)/src/github.com/cpuguy83/go-md2man; \
git checkout 20f5889cbdc3c73dbd2862796665e7c465ade7d1; \
go install github.com/cpuguy83/go-md2man; \
fi
.install.ostree: .gopathok

50
test/e2e/diff_test.go Normal file
View File

@ -0,0 +1,50 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman diff", 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 diff of image", func() {
session := podmanTest.Podman([]string{"diff", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman diff bogus image", func() {
session := podmanTest.Podman([]string{"diff", "1234"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})
It("podman diff image with json output", func() {
session := podmanTest.Podman([]string{"diff", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})
})

62
test/e2e/exec_test.go Normal file
View File

@ -0,0 +1,62 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman exec", 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 exec into bogus container", func() {
session := podmanTest.Podman([]string{"exec", "foobar", "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})
It("podman exec without command", func() {
session := podmanTest.Podman([]string{"exec", "foobar"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(125))
})
It("podman exec simple command", func() {
setup := podmanTest.RunSleepContainer("test1")
setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0))
session := podmanTest.Podman([]string{"exec", "test1", "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
It("podman exec simple command using latest", func() {
setup := podmanTest.RunSleepContainer("test1")
setup.WaitWithDefaultTimeout()
Expect(setup.ExitCode()).To(Equal(0))
session := podmanTest.Podman([]string{"exec", "-l", "ls"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
})

46
test/e2e/export_test.go Normal file
View File

@ -0,0 +1,46 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"path/filepath"
)
var _ = Describe("Podman export", 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 export output flag", func() {
_, ec, cid := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
outfile := filepath.Join(podmanTest.TempDir, "container.tar")
result := podmanTest.Podman([]string{"export", "-o", outfile, cid})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
_, err := os.Stat(outfile)
Expect(err).To(BeNil())
err = os.Remove(outfile)
Expect(err).To(BeNil())
})
})

72
test/e2e/history_test.go Normal file
View File

@ -0,0 +1,72 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman history", 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 history output flag", func() {
session := podmanTest.Podman([]string{"history", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman history with GO template", func() {
session := podmanTest.Podman([]string{"history", "--format", "{{.ID}} {{.Created}}", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman history with human flag", func() {
session := podmanTest.Podman([]string{"history", "--human=false", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman history with quiet flag", func() {
session := podmanTest.Podman([]string{"history", "-qH", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman history with no-trunc flag", func() {
session := podmanTest.Podman([]string{"history", "--no-trunc", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(BeNumerically(">", 0))
})
It("podman history with json flag", func() {
session := podmanTest.Podman([]string{"history", "--format=json", ALPINE})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.IsJSONOutputValid()).To(BeTrue())
})
})

89
test/e2e/run_cpu_test.go Normal file
View File

@ -0,0 +1,89 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman run cpu", 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 run cpu-period", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpu-period=5000", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_period_us"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("5000"))
})
It("podman run cpu-quota", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("5000"))
})
It("podman run cpus", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpus=0.5", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_period_us"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("100000"))
result = podmanTest.Podman([]string{"run", "--rm", "--cpus=0.5", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.cfs_quota_us"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("50000"))
})
It("podman run cpu-shares", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpu-shares=2", ALPINE, "cat", "/sys/fs/cgroup/cpu/cpu.shares"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("2"))
})
It("podman run cpuset-cpus", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpuset-cpus=0", ALPINE, "cat", "/sys/fs/cgroup/cpuset/cpuset.cpus"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("0"))
})
It("podman run cpuset-mems", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpuset-mems=0", ALPINE, "cat", "/sys/fs/cgroup/cpuset/cpuset.mems"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal("0"))
})
It("podman run cpus and cpu-period", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpu-period=5000", "--cpus=0.5", ALPINE, "ls"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Not(Equal(0)))
})
It("podman run cpus and cpu-quota", func() {
result := podmanTest.Podman([]string{"run", "--rm", "--cpu-quota=5000", "--cpus=0.5", ALPINE, "ls"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Not(Equal(0)))
})
})

View File

@ -0,0 +1,43 @@
package integration
import (
"os"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Podman kill", 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 run bad device test", func() {
session := podmanTest.Podman([]string{"run", "-q", "--device", "/dev/baddevice", ALPINE, "ls", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Not(Equal(0)))
})
It("podman run device test", func() {
session := podmanTest.Podman([]string{"run", "-q", "--device", "/dev/kmsg", ALPINE, "ls", "--color=never", "/dev/kmsg"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(Equal("/dev/kmsg"))
})
})

View File

@ -1,29 +0,0 @@
#!/usr/bin/env bats
load helpers
function setup() {
copy_images
}
function teardown() {
cleanup_test
}
@test "test diff of image and parent" {
run ${PODMAN_BINARY} $PODMAN_OPTIONS diff $BB
echo "$output"
[ "$status" -eq 0 ]
}
@test "test diff on non-existent layer" {
run ${PODMAN_BINARY} $PODMAN_OPTIONS diff "abc123"
echo "$output"
[ "$status" -ne 0 ]
}
@test "test diff with json output" {
run ${PODMAN_BINARY} $PODMAN_OPTIONS diff --format json $BB
echo "$output"
[ "$status" -eq 0 ]
}

View File

@ -1,37 +0,0 @@
#!/usr/bin/env bats
load helpers
function teardown() {
cleanup_test
}
function setup() {
copy_images
}
@test "exec into a bogus container" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} exec foobar ls
echo "$output"
[ "$status" -eq 125 ]
}
@test "exec without command should fail" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} exec foobar
echo "$output"
[ "$status" -eq 125 ]
}
@test "exec simple command" {
${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d -t --name foobar1 ${ALPINE} sleep 60
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} exec foobar1 ls
echo "$output"
[ "$status" -eq 0 ]
}
@test "exec simple command using latest" {
${PODMAN_BINARY} ${PODMAN_OPTIONS} run -d -t ${ALPINE} sleep 60
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} exec -l ls
echo "$output"
[ "$status" -eq 0 ]
}

View File

@ -1,25 +0,0 @@
#!/usr/bin/env bats
load helpers
function teardown() {
cleanup_test
}
function setup() {
copy_images
}
@test "podman export output flag" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} create $BB ls
echo "$output"
[ "$status" -eq 0 ]
ctr_id="$output"
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} export -o container.tar $ctr_id
echo "$output"
[ "$status" -eq 0 ]
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} rm $ctr_id
echo "$output"
[ "$status" -eq 0 ]
rm -f container.tar
}

View File

@ -1,53 +0,0 @@
#!/usr/bin/env bats
load helpers
function teardown() {
cleanup_test
}
function setup() {
copy_images
}
@test "podman history default" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history with Go template format" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history --format "{{.ID}} {{.Created}}" $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history human flag" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history --human=false $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history quiet flag" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history -q $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history no-trunc flag" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history --no-trunc $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history json flag" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} history --format json $ALPINE | python -m json.tool"
echo "$output"
[ "$status" -eq 0 ]
}
@test "podman history short options" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} history -qH $ALPINE
echo "$output"
[ "$status" -eq 0 ]
}

View File

@ -1,71 +0,0 @@
#!/usr/bin/env bats
load helpers
function teardown() {
cleanup_test
}
function setup() {
copy_images
}
@test "run cpu-period test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpu-period=5000 ${ALPINE} cat /sys/fs/cgroup/cpu/cpu.cfs_period_us | tr -d '\r'"
echo $output
[ "$status" -eq 0 ]
[ "$output" = 5000 ]
}
@test "run cpu-quota test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpu-quota=5000 ${ALPINE} cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 5000 ]
}
@test "run cpus test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpus=0.5 ${ALPINE} cat /sys/fs/cgroup/cpu/cpu.cfs_period_us | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 100000 ]
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpus=0.5 ${ALPINE} cat /sys/fs/cgroup/cpu/cpu.cfs_quota_us | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 50000 ]
}
@test "run cpu-shares test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpu-shares=2 ${ALPINE} cat /sys/fs/cgroup/cpu/cpu.shares | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 2 ]
}
@test "run cpuset-cpus test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpuset-cpus=0 ${ALPINE} cat /sys/fs/cgroup/cpuset/cpuset.cpus | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 0 ]
}
@test "run cpuset-mems test" {
run bash -c "${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpuset-mems=0 ${ALPINE} cat /sys/fs/cgroup/cpuset/cpuset.mems | tr -d '\r'"
echo "$output"
[ "$status" -eq 0 ]
[ "$output" = 0 ]
}
@test "run failure if cpus and cpu-period set together test" {
# skip, error code incorrect with bash -c and will fail centos test without bash -c
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpu-period=5000 --cpus=0.5 ${ALPINE} /bin/bash
echo "$output"
[ "$status" -ne 0 ]
}
@test "run failure if cpus and cpu-quota set together test" {
# skip, error code incorrect with bash -c and will fail centos test without bash -c
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run --rm --cpu-quota=5000 --cpus=0.5 ${ALPINE} /bin/bash
echo "$output"
[ "$status" -ne 0 ]
}

View File

@ -1,26 +0,0 @@
#!/usr/bin/env bats
load helpers
function teardown() {
cleanup_test
}
function setup() {
copy_images
}
@test "run baddevice test" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -q --device /dev/baddevice ${ALPINE} ls /dev/kmsg
echo $output
[ "$status" -ne 0 ]
}
@test "run device test" {
run ${PODMAN_BINARY} ${PODMAN_OPTIONS} run -q --device /dev/kmsg ${ALPINE} ls --color=never /dev/kmsg
echo "$output"
[ "$status" -eq 0 ]
device=$(echo $output | tr -d '\r')
echo "<$device>"
[ "$device" = "/dev/kmsg" ]
}