diff options
Diffstat (limited to 'test')
71 files changed, 678 insertions, 363 deletions
diff --git a/test/apiv2/12-imagesMore.at b/test/apiv2/12-imagesMore.at index 144b83194..3a5d5c096 100644 --- a/test/apiv2/12-imagesMore.at +++ b/test/apiv2/12-imagesMore.at @@ -47,8 +47,7 @@ t POST "images/localhost:5000/myrepo/push?tlsVerify=false&tag=mytag" 200 t POST "libpod/images/$iid/untag?repo=localhost:5000/myrepo&tag=mytag" 201 # Try to push non-existing image -t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" 200 -jq -re 'select(.errorDetail)' <<<"$output" &>/dev/null || echo -e "${red}not ok: error message not found in output${nc}" 1>&2 +t POST "images/localhost:5000/idonotexist/push?tlsVerify=false" 404 t GET libpod/images/$IMAGE/json 200 \ .RepoTags[-1]=$IMAGE diff --git a/test/apiv2/70-short-names.at b/test/apiv2/70-short-names.at new file mode 100644 index 000000000..a5087c115 --- /dev/null +++ b/test/apiv2/70-short-names.at @@ -0,0 +1,148 @@ +# -*- sh -*- +# +# Tests for exercising short-name resolution in the compat API. +# + +# Pull the libpod/quay image which is used in all tests below. +t POST "images/create?fromImage=quay.io/libpod/alpine:latest" 200 .error~null .status~".*Download complete.*" + + +########## TAG + +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t DELETE "images/foo" 200 + + +########## BUILD + +function test_build { + from=$1 + tag=$2 + fqn=$3 + + TMPD=$(mktemp -d podman-apiv2-test.build.XXXXXXXX) + CONTAINERFILE_TAR="${TMPD}/containerfile.tar" + cat > $TMPD/containerfile << EOF +FROM $from +RUN touch /foo +EOF + tar --format=posix -C $TMPD -cvf ${CONTAINERFILE_TAR} containerfile &> /dev/null + + curl -XPOST --data-binary @<(cat $CONTAINERFILE_TAR) \ + -H "content-type: application/x-tar" \ + --dump-header "${TMPD}/headers.txt" \ + -o "${TMPD}/response.txt" \ + "http://$HOST:$PORT/build?dockerfile=containerfile&t=$tag" &> /dev/null + + if ! grep -q '200 OK' "${TMPD}/headers.txt"; then + cat "${TMPD}/headers.txt" + cat "${TMPD}/response.txt" + echo -e "${red}NOK: Image build from tar failed response was not 200 OK (application/x-tar)" + exit 1 + fi + + rm -rf $TMPD + t DELETE "images/$fqn" 200 +} + +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +test_build foo bar "docker.io/library/bar:latest" +t DELETE "images/foo" 200 + + +########## TAG + +# Looking up 'alpine' will fail as it gets normalized to docker.io. +t POST "images/alpine/tag?repo=foo" 404 .cause="image not known" + +# The libpod endpoint will resolve to it without issues. +t GET "libpod/images/alpine/exists" 204 + +# Now let's tag the image with 'foo'. Remember, it will be normalized to +# docker.io/library/foo. +t GET "libpod/images/docker.io/library/foo/exists" 404 +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t GET "libpod/images/docker.io/library/foo/exists" 204 + + +########## REMOVE + +t DELETE "images/alpine" 404 .cause="image not known" # fails since docker.io/library/alpine does not exist +t DELETE "images/foo" 200 # removes the previously tagged image + + +########## GET + +# Same procedure as above but with the /get endpoint. +t GET "images/alpine/get" 404 .cause="image not known" +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t GET "images/foo/get" 200 '[POSIX tar archive]' +t DELETE "images/foo" 200 + + +########## HISTORY + +t GET "images/alpine/history" 404 .cause="image not known" +t GET "images/quay.io/libpod/alpine/history" 200 +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t GET "libpod/images/foo/history" 200 +t DELETE "images/foo" 200 + + +########## PUSH + +t POST "images/alpine/push?destination=localhost:9999/do/not:exist" 404 .cause="image not known" +t POST "images/quay.io/libpod/alpine/push?destination=localhost:9999/do/not:exist" 200 # Error is in the response +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t POST "images/foo/push?destination=localhost:9999/do/not:exist" 200 # Error is in the response +t DELETE "images/foo" 200 + + +########## CREATE A CONTAINER + +t POST "containers/create" Image=alpine 404 .cause="image not known" +t POST "containers/create" Image=quay.io/libpod/alpine:latest 201 +cid=$(jq -r '.Id' <<<"$output") +t POST "images/quay.io/libpod/alpine/tag?repo=foo" 201 +t POST "containers/create" Image=foo 201 +cid=$(jq -r '.Id' <<<"$output") +t DELETE "images/foo" 200 +t DELETE "containers/$cid" 204 + +########## COMMIT CONTAINER + +t POST "containers/create" Image=quay.io/libpod/alpine:latest 201 +cid=$(jq -r '.Id' <<<"$output") +t GET "images/alpine/get" 404 .cause="image not known" +t POST "commit?container=$cid&repo=foo&tag=tag" 201 +t GET "images/foo/get" 404 .cause="image not known" +t GET "images/foo:tag/get" 200 +t DELETE "images/docker.io/library/foo:tag" 200 +t DELETE "containers/$cid" 204 + + +######### SMOKE TESTS WITHOUT DOCKER.IO ENFORCEMENT + +# Note that we need to restart the service with a custom containers.conf to +# disable the docker.io enforcement. + +stop_service +CONTAINERS_CONF=$(pwd)/test/apiv2/containers.conf start_service + +t POST "images/create?fromImage=quay.io/libpod/alpine:latest" 200 .error~null .status~".*Download complete.*" +t POST "images/alpine/tag?repo=foo" 201 +t GET "images/localhost/foo:latest/get" 200 +t DELETE "images/foo" 200 +t GET "images/alpine/history" 200 +t POST "images/alpine/push?destination=localhost:9999/do/not:exist" 200 # Error is in the response +t POST "containers/create" Image=alpine 201 +cid=$(jq -r '.Id' <<<"$output") +t POST "commit?container=$cid&repo=foo&tag=tag" 201 +t DELETE "images/localhost/foo:tag" 200 +t DELETE "containers/$cid" 204 + +test_build alpine bar "localhost/bar:latest" + + +stop_service +start_service diff --git a/test/apiv2/containers.conf b/test/apiv2/containers.conf new file mode 100644 index 000000000..24762192f --- /dev/null +++ b/test/apiv2/containers.conf @@ -0,0 +1,8 @@ +# This containers.conf file is used to test enforcing short-name resolution to +# docker.io for Podman's *compat* API. By default, the compat API defaults to +# resolving to docker.io only. The behavior can be altered by configuring the +# containers.conf as done below in which case short names are subject to aliases, +# "localhost/" and the unqualified-search registries. + +[engine] +compat_api_enforce_docker_hub=false diff --git a/test/e2e/build/Dockerfile.with-multiple-secret b/test/e2e/build/Dockerfile.with-multiple-secret new file mode 100644 index 000000000..f3478914f --- /dev/null +++ b/test/e2e/build/Dockerfile.with-multiple-secret @@ -0,0 +1,3 @@ +FROM alpine +RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret +RUN --mount=type=secret,id=mysecret2 cat /run/secrets/mysecret2 diff --git a/test/e2e/build/Dockerfile.with-secret b/test/e2e/build/Dockerfile.with-secret new file mode 100644 index 000000000..920663a92 --- /dev/null +++ b/test/e2e/build/Dockerfile.with-secret @@ -0,0 +1,2 @@ +FROM alpine +RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret diff --git a/test/e2e/build/Dockerfile.with-secret-verify-leak b/test/e2e/build/Dockerfile.with-secret-verify-leak new file mode 100644 index 000000000..0957ac6a6 --- /dev/null +++ b/test/e2e/build/Dockerfile.with-secret-verify-leak @@ -0,0 +1,3 @@ +FROM alpine +COPY * / +RUN --mount=type=secret,id=mysecret cat /run/secrets/mysecret diff --git a/test/e2e/build/anothersecret.txt b/test/e2e/build/anothersecret.txt new file mode 100644 index 000000000..bc5fdbd32 --- /dev/null +++ b/test/e2e/build/anothersecret.txt @@ -0,0 +1 @@ +anothersecret diff --git a/test/e2e/build/secret.txt b/test/e2e/build/secret.txt new file mode 100644 index 000000000..d9106c0af --- /dev/null +++ b/test/e2e/build/secret.txt @@ -0,0 +1 @@ +somesecret diff --git a/test/e2e/build_test.go b/test/e2e/build_test.go index 420ed929f..5e93f9078 100644 --- a/test/e2e/build_test.go +++ b/test/e2e/build_test.go @@ -59,6 +59,45 @@ var _ = Describe("Podman build", func() { Expect(session).Should(Exit(0)) }) + It("podman build with a secret from file", func() { + session := podmanTest.Podman([]string{"build", "-f", "build/Dockerfile.with-secret", "-t", "secret-test", "--secret", "id=mysecret,src=build/secret.txt", "build/"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(ContainSubstring("somesecret")) + + session = podmanTest.Podman([]string{"rmi", "secret-test"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + }) + + It("podman build with multiple secrets from files", func() { + session := podmanTest.Podman([]string{"build", "-f", "build/Dockerfile.with-multiple-secret", "-t", "multiple-secret-test", "--secret", "id=mysecret,src=build/secret.txt", "--secret", "id=mysecret2,src=build/anothersecret.txt", "build/"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(ContainSubstring("somesecret")) + Expect(session.OutputToString()).To(ContainSubstring("anothersecret")) + + session = podmanTest.Podman([]string{"rmi", "multiple-secret-test"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + }) + + It("podman build with a secret from file and verify if secret file is not leaked into image", func() { + session := podmanTest.Podman([]string{"build", "-f", "build/Dockerfile.with-secret-verify-leak", "-t", "secret-test-leak", "--secret", "id=mysecret,src=build/secret.txt", "build/"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(ContainSubstring("somesecret")) + + session = podmanTest.Podman([]string{"run", "--rm", "secret-test-leak", "ls"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(Not(ContainSubstring("podman-build-secret"))) + + session = podmanTest.Podman([]string{"rmi", "secret-test-leak"}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + }) + It("podman build with logfile", func() { logfile := filepath.Join(podmanTest.TempDir, "logfile") session := podmanTest.Podman([]string{"build", "--pull-never", "--tag", "test", "--logfile", logfile, "build/basicalpine"}) @@ -388,13 +427,10 @@ subdir**` session := podmanTest.Podman([]string{"build", "-t", "test", "."}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, _ := session.GrepString("/testfilter/dummy1") - Expect(ok).NotTo(BeTrue()) - Expect(session.OutputToString()).To(ContainSubstring("/testfilter/dummy2")) - ok, _ = session.GrepString("/testfilter/subdir") - Expect(ok).NotTo(BeTrue()) //.dockerignore filters both subdir and inside subdir - ok, _ = session.GrepString("/testfilter/subdir/dummy3") - Expect(ok).NotTo(BeTrue()) + output := session.OutputToString() + Expect(output).To(ContainSubstring("/testfilter/dummy2")) + Expect(output).NotTo(ContainSubstring("/testfilter/dummy1")) + Expect(output).NotTo(ContainSubstring("/testfilter/subdir")) }) It("podman remote test context dir contains empty dirs and symlinks", func() { diff --git a/test/e2e/checkpoint_test.go b/test/e2e/checkpoint_test.go index cc827a453..5a2640f33 100644 --- a/test/e2e/checkpoint_test.go +++ b/test/e2e/checkpoint_test.go @@ -102,7 +102,7 @@ var _ = Describe("Podman checkpoint", func() { inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) inspectOut := inspect.InspectContainerToJSON() - Expect(inspectOut[0].State.Checkpointed).To(BeTrue()) + Expect(inspectOut[0].State.Checkpointed).To(BeTrue(), ".State.Checkpointed") result = podmanTest.Podman([]string{"container", "restore", cid}) result.WaitWithDefaultTimeout() @@ -192,7 +192,7 @@ var _ = Describe("Podman checkpoint", func() { ps.WaitWithDefaultTimeout() Expect(ps).Should(Exit(0)) Expect(ps.OutputToString()).To(ContainSubstring(session1.OutputToString())) - Expect(ps.LineInOutputContains(session2.OutputToString())).To(BeFalse()) + Expect(ps.OutputToString()).To(Not(ContainSubstring(session2.OutputToString()))) result = podmanTest.Podman([]string{"container", "restore", "second"}) result.WaitWithDefaultTimeout() @@ -228,8 +228,8 @@ var _ = Describe("Podman checkpoint", func() { ps := podmanTest.Podman([]string{"ps", "-q", "--no-trunc"}) ps.WaitWithDefaultTimeout() Expect(ps).Should(Exit(0)) - Expect(ps.LineInOutputContains(session1.OutputToString())).To(BeFalse()) - Expect(ps.LineInOutputContains(session2.OutputToString())).To(BeFalse()) + Expect(ps.OutputToString()).To(Not(ContainSubstring(session1.OutputToString()))) + Expect(ps.OutputToString()).To(Not(ContainSubstring(session2.OutputToString()))) result = podmanTest.Podman([]string{"container", "restore", "-a"}) result.WaitWithDefaultTimeout() @@ -1019,6 +1019,9 @@ var _ = Describe("Podman checkpoint", func() { "podman checkpoint and restore container out of and into pod (%s)", share, ) + + share := share // copy into local scope, for use inside function + It(testName, func() { if !criu.CheckForCriu(criu.PodCriuVersion) { Skip("CRIU is missing or too old.") @@ -1294,8 +1297,8 @@ var _ = Describe("Podman checkpoint", func() { }) ps.WaitWithDefaultTimeout() Expect(ps).Should(Exit(0)) - Expect(ps.LineInOutputContains(session1.OutputToString())).To(BeFalse()) - Expect(ps.LineInOutputContains(session2.OutputToString())).To(BeFalse()) + Expect(ps.OutputToString()).To(Not(ContainSubstring(session1.OutputToString()))) + Expect(ps.OutputToString()).To(Not(ContainSubstring(session2.OutputToString()))) result = podmanTest.Podman([]string{ "container", diff --git a/test/e2e/commit_test.go b/test/e2e/commit_test.go index 20e1360de..a09666468 100644 --- a/test/e2e/commit_test.go +++ b/test/e2e/commit_test.go @@ -204,8 +204,7 @@ var _ = Describe("Podman commit", func() { inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) image := inspect.InspectImageJSON() - _, ok := image[0].Config.Volumes["/foo"] - Expect(ok).To(BeFalse()) + Expect(image[0].Config.Volumes).To(Not(HaveKey("/foo"))) }) It("podman commit with volume mounts and --include-volumes", func() { @@ -224,8 +223,7 @@ var _ = Describe("Podman commit", func() { inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) image := inspect.InspectImageJSON() - _, ok := image[0].Config.Volumes["/foo"] - Expect(ok).To(BeTrue()) + Expect(image[0].Config.Volumes).To(HaveKey("/foo")) r := podmanTest.Podman([]string{"run", "newimage"}) r.WaitWithDefaultTimeout() @@ -250,7 +248,7 @@ var _ = Describe("Podman commit", func() { for _, v := range image[0].Config.Env { envMap[v] = true } - Expect(envMap["TEST=1=1-01=9.01"]).To(BeTrue()) + Expect(envMap).To(HaveKey("TEST=1=1-01=9.01")) }) It("podman commit container and print id to external file", func() { diff --git a/test/e2e/common_test.go b/test/e2e/common_test.go index 6180343a7..63cb4f091 100644 --- a/test/e2e/common_test.go +++ b/test/e2e/common_test.go @@ -24,7 +24,6 @@ import ( "github.com/containers/storage/pkg/reexec" "github.com/containers/storage/pkg/stringid" jsoniter "github.com/json-iterator/go" - "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -33,16 +32,14 @@ import ( ) var ( - PODMAN_BINARY string - CONMON_BINARY string - CNI_CONFIG_DIR string - RUNC_BINARY string - INTEGRATION_ROOT string - CGROUP_MANAGER = "systemd" - ARTIFACT_DIR = "/tmp/.artifacts" - RESTORE_IMAGES = []string{ALPINE, BB, nginx} + //lint:ignore ST1003 + PODMAN_BINARY string //nolint:golint,stylecheck + INTEGRATION_ROOT string //nolint:golint,stylecheck + CGROUP_MANAGER = "systemd" //nolint:golint,stylecheck + ARTIFACT_DIR = "/tmp/.artifacts" //nolint:golint,stylecheck + RESTORE_IMAGES = []string{ALPINE, BB, nginx} //nolint:golint,stylecheck defaultWaitTimeout = 90 - CGROUPSV2, _ = cgroups.IsCgroup2UnifiedMode() + CGROUPSV2, _ = cgroups.IsCgroup2UnifiedMode() //nolint:golint,stylecheck ) // PodmanTestIntegration struct for command line options @@ -74,8 +71,6 @@ type testResult struct { length float64 } -var noCache = "Cannot run nocache with remote" - type testResultsSorted []testResult func (a testResultsSorted) Len() int { return len(a) } @@ -475,7 +470,7 @@ func (p *PodmanTestIntegration) PodmanPID(args []string) (*PodmanSessionIntegrat if err != nil { Fail(fmt.Sprintf("unable to run podman command: %s", strings.Join(podmanOptions, " "))) } - podmanSession := &PodmanSession{session} + podmanSession := &PodmanSession{Session: session} return &PodmanSessionIntegration{podmanSession}, command.Process.Pid } @@ -597,9 +592,9 @@ func (p *PodmanTestIntegration) RunHealthCheck(cid string) error { return errors.Errorf("unable to detect %s as running", cid) } -func (p *PodmanTestIntegration) CreateSeccompJson(in []byte) (string, error) { +func (p *PodmanTestIntegration) CreateSeccompJSON(in []byte) (string, error) { jsonFile := filepath.Join(p.TempDir, "seccomp.json") - err := WriteJsonFile(in, jsonFile) + err := WriteJSONFile(in, jsonFile) if err != nil { return "", err } @@ -622,14 +617,14 @@ func SkipIfRootlessCgroupsV1(reason string) { func SkipIfRootless(reason string) { checkReason(reason) if os.Geteuid() != 0 { - ginkgo.Skip("[rootless]: " + reason) + Skip("[rootless]: " + reason) } } func SkipIfNotRootless(reason string) { checkReason(reason) if os.Geteuid() == 0 { - ginkgo.Skip("[notRootless]: " + reason) + Skip("[notRootless]: " + reason) } } @@ -640,7 +635,7 @@ func SkipIfSystemdNotRunning(reason string) { err := cmd.Run() if err != nil { if _, ok := err.(*exec.Error); ok { - ginkgo.Skip("[notSystemd]: not running " + reason) + Skip("[notSystemd]: not running " + reason) } Expect(err).ToNot(HaveOccurred()) } @@ -649,14 +644,14 @@ func SkipIfSystemdNotRunning(reason string) { func SkipIfNotSystemd(manager, reason string) { checkReason(reason) if manager != "systemd" { - ginkgo.Skip("[notSystemd]: " + reason) + Skip("[notSystemd]: " + reason) } } func SkipIfNotFedora() { info := GetHostDistributionInfo() if info.Distribution != "fedora" { - ginkgo.Skip("Test can only run on Fedora") + Skip("Test can only run on Fedora") } } @@ -684,10 +679,7 @@ func SkipIfCgroupV2(reason string) { func isContainerized() bool { // This is set to "podman" by podman automatically - if os.Getenv("container") != "" { - return true - } - return false + return os.Getenv("container") != "" } func SkipIfContainerized(reason string) { @@ -702,7 +694,7 @@ func SkipIfRemote(reason string) { if !IsRemote() { return } - ginkgo.Skip("[remote]: " + reason) + Skip("[remote]: " + reason) } // SkipIfInContainer skips a test if the test is run inside a container @@ -872,10 +864,10 @@ func (p *PodmanTestIntegration) removeCNINetwork(name string) { Expect(session.ExitCode()).To(BeNumerically("<=", 1), "Exit code must be 0 or 1") } -func (p *PodmanSessionIntegration) jq(jqCommand string) (string, error) { +func (s *PodmanSessionIntegration) jq(jqCommand string) (string, error) { var out bytes.Buffer cmd := exec.Command("jq", jqCommand) - cmd.Stdin = strings.NewReader(p.OutputToString()) + cmd.Stdin = strings.NewReader(s.OutputToString()) cmd.Stdout = &out err := cmd.Run() return strings.TrimRight(out.String(), "\n"), err diff --git a/test/e2e/config_amd64.go b/test/e2e/config_amd64.go index 3607bdc30..9293fdd44 100644 --- a/test/e2e/config_amd64.go +++ b/test/e2e/config_amd64.go @@ -1,16 +1,16 @@ package integration var ( - STORAGE_FS = "vfs" - STORAGE_OPTIONS = "--storage-driver vfs" - ROOTLESS_STORAGE_FS = "vfs" - ROOTLESS_STORAGE_OPTIONS = "--storage-driver vfs" - CACHE_IMAGES = []string{ALPINE, BB, fedoraMinimal, nginx, redis, registry, infra, labels, healthcheck, ubi_init, ubi_minimal, fedoraToolbox} + STORAGE_FS = "vfs" //nolint:golint,stylecheck + STORAGE_OPTIONS = "--storage-driver vfs" //nolint:golint,stylecheck + ROOTLESS_STORAGE_FS = "vfs" //nolint:golint,stylecheck + ROOTLESS_STORAGE_OPTIONS = "--storage-driver vfs" //nolint:golint,stylecheck + CACHE_IMAGES = []string{ALPINE, BB, fedoraMinimal, nginx, redis, registry, infra, labels, healthcheck, UBI_INIT, UBI_MINIMAL, fedoraToolbox} //nolint:golint,stylecheck nginx = "quay.io/libpod/alpine_nginx:latest" - BB_GLIBC = "docker.io/library/busybox:glibc" + BB_GLIBC = "docker.io/library/busybox:glibc" //nolint:golint,stylecheck registry = "quay.io/libpod/registry:2.6" labels = "quay.io/libpod/alpine_labels:latest" - ubi_minimal = "registry.access.redhat.com/ubi8-minimal" - ubi_init = "registry.access.redhat.com/ubi8-init" + UBI_MINIMAL = "registry.access.redhat.com/ubi8-minimal" //nolint:golint,stylecheck + UBI_INIT = "registry.access.redhat.com/ubi8-init" //nolint:golint,stylecheck cirros = "quay.io/libpod/cirros:latest" ) diff --git a/test/e2e/container_create_volume_test.go b/test/e2e/container_create_volume_test.go index 001698239..0dac96a5e 100644 --- a/test/e2e/container_create_volume_test.go +++ b/test/e2e/container_create_volume_test.go @@ -28,7 +28,7 @@ VOLUME %s/`, data, dest, dest) func createContainersConfFile(pTest *PodmanTestIntegration) { configPath := filepath.Join(pTest.TempDir, "containers.conf") - containersConf := []byte(fmt.Sprintf("[containers]\nprepare_volume_on_create = true\n")) + containersConf := []byte("[containers]\nprepare_volume_on_create = true\n") err := ioutil.WriteFile(configPath, containersConf, os.ModePerm) Expect(err).To(BeNil()) diff --git a/test/e2e/containers_conf_test.go b/test/e2e/containers_conf_test.go index 6a760da17..2a6f177f2 100644 --- a/test/e2e/containers_conf_test.go +++ b/test/e2e/containers_conf_test.go @@ -245,7 +245,7 @@ var _ = Describe("Podman run", func() { session := podmanTest.Podman([]string{"run", "--dns-search=.", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputStartsWith("search")).To(BeFalse()) + Expect(session.OutputToStringArray()).To(Not(ContainElement(HavePrefix("search")))) }) It("podman run use containers.conf search domain", func() { @@ -407,7 +407,7 @@ var _ = Describe("Podman run", func() { configPath := filepath.Join(podmanTest.TempDir, "containers.conf") os.Setenv("CONTAINERS_CONF", configPath) - containersConf := []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"/foobar\"")) + containersConf := []byte("[engine]\nimage_copy_tmp_dir=\"/foobar\"") err = ioutil.WriteFile(configPath, containersConf, os.ModePerm) Expect(err).To(BeNil()) @@ -420,7 +420,7 @@ var _ = Describe("Podman run", func() { Expect(session).Should(Exit(0)) Expect(session.OutputToString()).To(Equal("/foobar")) - containersConf = []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"storage\"")) + containersConf = []byte("[engine]\nimage_copy_tmp_dir=\"storage\"") err = ioutil.WriteFile(configPath, containersConf, os.ModePerm) Expect(err).To(BeNil()) if IsRemote() { @@ -432,7 +432,7 @@ var _ = Describe("Podman run", func() { Expect(session).Should(Exit(0)) Expect(session.OutputToString()).To(ContainSubstring("containers/storage/tmp")) - containersConf = []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"storage1\"")) + containersConf = []byte("[engine]\nimage_copy_tmp_dir=\"storage1\"") err = ioutil.WriteFile(configPath, containersConf, os.ModePerm) Expect(err).To(BeNil()) if IsRemote() { diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go index 216432216..321361382 100644 --- a/test/e2e/create_test.go +++ b/test/e2e/create_test.go @@ -107,9 +107,7 @@ var _ = Describe("Podman create", func() { check := podmanTest.Podman([]string{"inspect", "annotate_test"}) check.WaitWithDefaultTimeout() data := check.InspectContainerToJSON() - value, ok := data[0].Config.Annotations["HELLO"] - Expect(ok).To(BeTrue()) - Expect(value).To(Equal("WORLD")) + Expect(data[0].Config.Annotations).To(HaveKeyWithValue("HELLO", "WORLD")) }) It("podman create --entrypoint command", func() { @@ -202,7 +200,7 @@ var _ = Describe("Podman create", func() { Expect(session).Should(Exit(0)) Expect(session.OutputToString()).To(ContainSubstring("/create/test ro")) - session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_shared", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,shared", mountPath), ALPINE, "grep", "/create/test", "/proc/self/mountinfo"}) + session = podmanTest.Podman([]string{"create", "--log-driver", "k8s-file", "--name", "test_shared", "--mount", fmt.Sprintf("type=bind,src=%s,target=/create/test,shared", mountPath), ALPINE, "awk", `$5 == "/create/test" { print $6 " " $7}`, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"start", "test_shared"}) @@ -211,10 +209,8 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"logs", "test_shared"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - found, matches := session.GrepString("/create/test") - Expect(found).Should(BeTrue()) - Expect(matches[0]).To(ContainSubstring("rw")) - Expect(matches[0]).To(ContainSubstring("shared")) + Expect(session.OutputToString()).To(ContainSubstring("rw")) + Expect(session.OutputToString()).To(ContainSubstring("shared")) mountPath = filepath.Join(podmanTest.TempDir, "scratchpad") os.Mkdir(mountPath, 0755) @@ -263,7 +259,7 @@ var _ = Describe("Podman create", func() { session = podmanTest.Podman([]string{"pod", "inspect", podName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) podData := session.InspectPodToJSON() // Finally we can create a container with --pod-id-file and do @@ -386,12 +382,10 @@ var _ = Describe("Podman create", func() { inspect := podmanTest.Podman([]string{"inspect", ctrName}) inspect.WaitWithDefaultTimeout() data := inspect.InspectContainerToJSON() - Expect(len(data)).To(Equal(1)) + Expect(len(data)).To(Equal(1), "len(InspectContainerToJSON)") Expect(len(data[0].Config.Labels)).To(Equal(2)) - _, ok1 := data[0].Config.Labels["TESTKEY1"] - Expect(ok1).To(BeTrue()) - _, ok2 := data[0].Config.Labels["TESTKEY2"] - Expect(ok2).To(BeTrue()) + Expect(data[0].Config.Labels).To(HaveKey("TESTKEY1")) + Expect(data[0].Config.Labels).To(HaveKey("TESTKEY2")) }) It("podman create with set label", func() { @@ -406,12 +400,8 @@ var _ = Describe("Podman create", func() { data := inspect.InspectContainerToJSON() Expect(len(data)).To(Equal(1)) Expect(len(data[0].Config.Labels)).To(Equal(2)) - val1, ok1 := data[0].Config.Labels["TESTKEY1"] - Expect(ok1).To(BeTrue()) - Expect(val1).To(Equal("value1")) - val2, ok2 := data[0].Config.Labels["TESTKEY2"] - Expect(ok2).To(BeTrue()) - Expect(val2).To(Equal("bar")) + Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY1", "value1")) + Expect(data[0].Config.Labels).To(HaveKeyWithValue("TESTKEY2", "bar")) }) It("podman create with --restart=on-failure:5 parses correctly", func() { diff --git a/test/e2e/diff_test.go b/test/e2e/diff_test.go index 71696f5b6..80647c6f5 100644 --- a/test/e2e/diff_test.go +++ b/test/e2e/diff_test.go @@ -53,7 +53,7 @@ var _ = Describe("Podman diff", func() { session := podmanTest.Podman([]string{"diff", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman diff container and committed image", func() { diff --git a/test/e2e/generate_kube_test.go b/test/e2e/generate_kube_test.go index a148025e5..735334eec 100644 --- a/test/e2e/generate_kube_test.go +++ b/test/e2e/generate_kube_test.go @@ -606,9 +606,7 @@ var _ = Describe("Podman generate kube", func() { pod := new(v1.Pod) err = yaml.Unmarshal(b, pod) Expect(err).To(BeNil()) - val, found := pod.Annotations[define.BindMountPrefix+vol1] - Expect(found).To(BeTrue()) - Expect(val).To(HaveSuffix("z")) + Expect(pod.Annotations).To(HaveKeyWithValue(define.BindMountPrefix+vol1, HaveSuffix("z"))) rm := podmanTest.Podman([]string{"pod", "rm", "-t", "0", "-f", "test1"}) rm.WaitWithDefaultTimeout() @@ -1071,9 +1069,7 @@ USER test1` err := yaml.Unmarshal(kube.Out.Contents(), pod) Expect(err).To(BeNil()) - v, ok := pod.GetAnnotations()["io.containers.autoupdate/top"] - Expect(ok).To(Equal(true)) - Expect(v).To(Equal("local")) + Expect(pod.GetAnnotations()).To(HaveKeyWithValue("io.containers.autoupdate/top", "local")) }) It("podman generate kube on pod with auto update labels in all containers", func() { @@ -1100,13 +1096,8 @@ USER test1` Expect(pod.Spec.Containers[1].WorkingDir).To(Equal("/root")) for _, ctr := range []string{"top1", "top2"} { - v, ok := pod.GetAnnotations()["io.containers.autoupdate/"+ctr] - Expect(ok).To(Equal(true)) - Expect(v).To(Equal("registry")) - - v, ok = pod.GetAnnotations()["io.containers.autoupdate.authfile/"+ctr] - Expect(ok).To(Equal(true)) - Expect(v).To(Equal("/some/authfile.json")) + Expect(pod.GetAnnotations()).To(HaveKeyWithValue("io.containers.autoupdate/"+ctr, "registry")) + Expect(pod.GetAnnotations()).To(HaveKeyWithValue("io.containers.autoupdate.authfile/"+ctr, "/some/authfile.json")) } }) }) diff --git a/test/e2e/generate_systemd_test.go b/test/e2e/generate_systemd_test.go index e93482535..1cffdc62e 100644 --- a/test/e2e/generate_systemd_test.go +++ b/test/e2e/generate_systemd_test.go @@ -420,7 +420,7 @@ var _ = Describe("Podman generate systemd", func() { session := podmanTest.Podman([]string{"generate", "systemd", "--format", "json", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman generate systemd --new create command with double curly braces", func() { diff --git a/test/e2e/history_test.go b/test/e2e/history_test.go index 0f0f6d38a..1f8faa6c2 100644 --- a/test/e2e/history_test.go +++ b/test/e2e/history_test.go @@ -89,6 +89,6 @@ var _ = Describe("Podman history", func() { session := podmanTest.Podman([]string{"history", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) }) diff --git a/test/e2e/image_scp_test.go b/test/e2e/image_scp_test.go index 63276e57f..6c6c85bc3 100644 --- a/test/e2e/image_scp_test.go +++ b/test/e2e/image_scp_test.go @@ -62,7 +62,7 @@ var _ = Describe("podman image scp", func() { }) It("podman image scp root to rootless transfer", func() { - SkipIfNotRootless("this is a rootless only test, transfering from root to rootless using PodmanAsUser") + SkipIfNotRootless("this is a rootless only test, transferring from root to rootless using PodmanAsUser") if IsRemote() { Skip("this test is only for non-remote") } diff --git a/test/e2e/image_sign_test.go b/test/e2e/image_sign_test.go index 6b87c9edd..09e156e02 100644 --- a/test/e2e/image_sign_test.go +++ b/test/e2e/image_sign_test.go @@ -73,6 +73,6 @@ var _ = Describe("Podman image sign", func() { Expect(session).Should(Exit(0)) fInfos, err := ioutil.ReadDir(filepath.Join(sigDir, "library")) Expect(err).To(BeNil()) - Expect(len(fInfos) > 1).To(BeTrue()) + Expect(len(fInfos)).To(BeNumerically(">", 1), "len(fInfos)") }) }) diff --git a/test/e2e/images_test.go b/test/e2e/images_test.go index 3ed8ef462..9cc04e6b0 100644 --- a/test/e2e/images_test.go +++ b/test/e2e/images_test.go @@ -94,14 +94,14 @@ var _ = Describe("Podman images", func() { session := podmanTest.Podman([]string{"images", "--format=json", "not-existing-image"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman images in JSON format", func() { session := podmanTest.Podman([]string{"images", "--format=json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman images in GO template format", func() { @@ -229,11 +229,10 @@ WORKDIR /test result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - found, _ := result.GrepString("<none>") if noneTag { - Expect(found).To(BeTrue()) + Expect(result.OutputToString()).To(ContainSubstring("<none>")) } else { - Expect(found).To(BeFalse()) + Expect(result.OutputToString()).To(Not(ContainSubstring("<none>"))) } } // No "<none>" tag as tagged alpine instances should be present. @@ -254,7 +253,7 @@ WORKDIR /test session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() result := podmanTest.Podman([]string{"images", "sha256:" + imageData[0].ID}) @@ -266,7 +265,7 @@ WORKDIR /test session := podmanTest.Podman([]string{"image", "inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() result := podmanTest.Podman([]string{"image", "ls", fmt.Sprintf("sha256:%s", imageData[0].ID)}) diff --git a/test/e2e/inspect_test.go b/test/e2e/inspect_test.go index 52726015c..0f0237adc 100644 --- a/test/e2e/inspect_test.go +++ b/test/e2e/inspect_test.go @@ -38,7 +38,7 @@ var _ = Describe("Podman inspect", func() { session := podmanTest.Podman([]string{"inspect", "--format=json", ALPINE}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) imageData := session.InspectImageJSON() Expect(imageData[0].RepoTags[0]).To(Equal("quay.io/libpod/alpine:latest")) }) @@ -314,7 +314,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -328,7 +328,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -343,7 +343,7 @@ var _ = Describe("Podman inspect", func() { inspect := podmanTest.Podman([]string{"inspect", "--type", "pod", "--latest"}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodArrToJSON() Expect(podData[0].Name).To(Equal(podName)) }) @@ -357,14 +357,14 @@ var _ = Describe("Podman inspect", func() { inspect1 := podmanTest.Podman([]string{"inspect", "--type", "pod", podName}) inspect1.WaitWithDefaultTimeout() Expect(inspect1).Should(Exit(0)) - Expect(inspect1.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect1.OutputToString()).To(BeValidJSON()) podData := inspect1.InspectPodArrToJSON() infra := podData[0].Containers[0].Name inspect := podmanTest.Podman([]string{"inspect", "--latest"}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) containerData := inspect.InspectContainerToJSON() Expect(containerData[0].Name).To(Equal(infra)) }) @@ -388,7 +388,7 @@ var _ = Describe("Podman inspect", func() { session = podmanTest.Podman([]string{"inspect", volName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman inspect a volume with --format", func() { diff --git a/test/e2e/libpod_suite_remote_test.go b/test/e2e/libpod_suite_remote_test.go index 1fa29daa1..2ecbd0eab 100644 --- a/test/e2e/libpod_suite_remote_test.go +++ b/test/e2e/libpod_suite_remote_test.go @@ -111,7 +111,6 @@ func (p *PodmanTestIntegration) StopRemoteService() { if _, err := remoteSession.Wait(); err != nil { fmt.Fprintf(os.Stderr, "error on remote stop-wait %q", err) } - } else { parentPid := fmt.Sprintf("%d", p.RemoteSession.Pid) pgrep := exec.Command("pgrep", "-P", parentPid) diff --git a/test/e2e/load_test.go b/test/e2e/load_test.go index 030e9f80b..ac70ebd8c 100644 --- a/test/e2e/load_test.go +++ b/test/e2e/load_test.go @@ -160,8 +160,7 @@ var _ = Describe("Podman load", func() { Expect(result).Should(Exit(125)) errMsg := fmt.Sprintf("remote client supports archives only but %q is a directory", podmanTest.TempDir) - found, _ := result.ErrorGrepString(errMsg) - Expect(found).Should(BeTrue()) + Expect(result.ErrorToString()).To(ContainSubstring(errMsg)) }) It("podman load bogus file", func() { @@ -221,7 +220,7 @@ var _ = Describe("Podman load", func() { result := podmanTest.Podman([]string{"images", "hello:world"}) result.WaitWithDefaultTimeout() - Expect(result.LineInOutputContains("docker")).To(Not(BeTrue())) + Expect(result.OutputToString()).To(Not(ContainSubstring("docker"))) Expect(result.OutputToString()).To(ContainSubstring("localhost")) }) @@ -246,7 +245,7 @@ var _ = Describe("Podman load", func() { result := podmanTest.Podman([]string{"images", "hello:latest"}) result.WaitWithDefaultTimeout() - Expect(result.LineInOutputContains("docker")).To(Not(BeTrue())) + Expect(result.OutputToString()).To(Not(ContainSubstring("docker"))) Expect(result.OutputToString()).To(ContainSubstring("localhost")) }) @@ -272,7 +271,7 @@ var _ = Describe("Podman load", func() { result := podmanTest.Podman([]string{"images", "load:latest"}) result.WaitWithDefaultTimeout() - Expect(result.LineInOutputContains("docker")).To(Not(BeTrue())) + Expect(result.OutputToString()).To(Not(ContainSubstring("docker"))) Expect(result.OutputToString()).To(ContainSubstring("localhost")) }) diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go index d901dde5c..2558af0eb 100644 --- a/test/e2e/logs_test.go +++ b/test/e2e/logs_test.go @@ -20,10 +20,7 @@ func isEventBackendJournald(podmanTest *PodmanTestIntegration) bool { } info := podmanTest.Podman([]string{"info", "--format", "{{.Host.EventLogger}}"}) info.WaitWithDefaultTimeout() - if info.OutputToString() == "journald" { - return true - } - return false + return info.OutputToString() == "journald" } var _ = Describe("Podman logs", func() { diff --git a/test/e2e/mount_test.go b/test/e2e/mount_test.go index 5ecd61097..0555a0749 100644 --- a/test/e2e/mount_test.go +++ b/test/e2e/mount_test.go @@ -78,7 +78,7 @@ var _ = Describe("Podman mount", func() { j := podmanTest.Podman([]string{"mount", "--format=json"}) j.WaitWithDefaultTimeout() Expect(j).Should(Exit(0)) - Expect(j.IsJSONOutputValid()).To(BeTrue()) + Expect(j.OutputToString()).To(BeValidJSON()) j = podmanTest.Podman([]string{"mount", "--format='{{.foobar}}'"}) j.WaitWithDefaultTimeout() @@ -332,7 +332,7 @@ var _ = Describe("Podman mount", func() { j := podmanTest.Podman([]string{"image", "mount", "--format=json"}) j.WaitWithDefaultTimeout() Expect(j).Should(Exit(0)) - Expect(j.IsJSONOutputValid()).To(BeTrue()) + Expect(j.OutputToString()).To(BeValidJSON()) umount := podmanTest.Podman([]string{"image", "umount", fedoraMinimal}) umount.WaitWithDefaultTimeout() diff --git a/test/e2e/network_test.go b/test/e2e/network_test.go index 953380335..d56cde9db 100644 --- a/test/e2e/network_test.go +++ b/test/e2e/network_test.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "os" - "strings" "time" "github.com/containers/podman/v3/libpod/network/types" @@ -141,7 +140,7 @@ var _ = Describe("Podman network", func() { session := podmanTest.Podman([]string{"network", "ls", "--filter", "label=abc"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains(name)).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring(name))) }) It("podman network ID test", func() { @@ -185,7 +184,7 @@ var _ = Describe("Podman network", func() { Expect(session).Should(Exit(0)) }) - rm_func := func(rm string) { + rmFunc := func(rm string) { It(fmt.Sprintf("podman network %s no args", rm), func() { session := podmanTest.Podman([]string{"network", rm}) session.WaitWithDefaultTimeout() @@ -209,12 +208,12 @@ var _ = Describe("Podman network", func() { results := podmanTest.Podman([]string{"network", "ls", "--quiet"}) results.WaitWithDefaultTimeout() Expect(results).Should(Exit(0)) - Expect(results.LineInOutputContains(name)).To(BeFalse()) + Expect(results.OutputToString()).To(Not(ContainSubstring(name))) }) } - rm_func("rm") - rm_func("remove") + rmFunc("rm") + rmFunc("remove") It("podman network inspect no args", func() { session := podmanTest.Podman([]string{"network", "inspect"}) @@ -234,7 +233,7 @@ var _ = Describe("Podman network", func() { session := podmanTest.Podman(append([]string{"network", "inspect"}, expectedNetworks...)) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman network inspect", func() { @@ -269,7 +268,7 @@ var _ = Describe("Podman network", func() { Expect(ok).To(BeTrue()) Expect(net.NetworkID).To(Equal(netName)) Expect(net.IPPrefixLen).To(Equal(24)) - Expect(strings.HasPrefix(net.IPAddress, "10.50.50.")).To(BeTrue()) + Expect(net.IPAddress).To(HavePrefix("10.50.50.")) // Necessary to ensure the CNI network is removed cleanly rmAll := podmanTest.Podman([]string{"rm", "-t", "0", "-f", ctrName}) @@ -342,12 +341,12 @@ var _ = Describe("Podman network", func() { Expect(ok).To(BeTrue()) Expect(net1.NetworkID).To(Equal(netName1)) Expect(net1.IPPrefixLen).To(Equal(25)) - Expect(strings.HasPrefix(net1.IPAddress, "10.50.51.")).To(BeTrue()) + Expect(net1.IPAddress).To(HavePrefix("10.50.51.")) net2, ok := conData[0].NetworkSettings.Networks[netName2] Expect(ok).To(BeTrue()) Expect(net2.NetworkID).To(Equal(netName2)) Expect(net2.IPPrefixLen).To(Equal(26)) - Expect(strings.HasPrefix(net2.IPAddress, "10.50.51.")).To(BeTrue()) + Expect(net2.IPAddress).To(HavePrefix("10.50.51.")) // Necessary to ensure the CNI network is removed cleanly rmAll := podmanTest.Podman([]string{"rm", "-t", "0", "-f", ctrName}) diff --git a/test/e2e/play_build_test.go b/test/e2e/play_build_test.go index 564735e07..9bdf9d06b 100644 --- a/test/e2e/play_build_test.go +++ b/test/e2e/play_build_test.go @@ -95,6 +95,7 @@ LABEL marge=mom // Setup yamlDir := filepath.Join(tempdir, RandomString(12)) err := os.Mkdir(yamlDir, 0755) + Expect(err).To(BeNil(), "mkdir "+yamlDir) err = writeYaml(testYAML, filepath.Join(yamlDir, "top.yaml")) Expect(err).To(BeNil()) app1Dir := filepath.Join(yamlDir, "foobar") @@ -131,6 +132,7 @@ LABEL marge=mom // Setup yamlDir := filepath.Join(tempdir, RandomString(12)) err := os.Mkdir(yamlDir, 0755) + Expect(err).To(BeNil(), "mkdir "+yamlDir) err = writeYaml(testYAML, filepath.Join(yamlDir, "top.yaml")) Expect(err).To(BeNil()) app1Dir := filepath.Join(yamlDir, "foobar") @@ -167,6 +169,7 @@ LABEL marge=mom // Setup yamlDir := filepath.Join(tempdir, RandomString(12)) err := os.Mkdir(yamlDir, 0755) + Expect(err).To(BeNil(), "mkdir "+yamlDir) err = writeYaml(testYAML, filepath.Join(yamlDir, "top.yaml")) Expect(err).To(BeNil()) @@ -213,6 +216,7 @@ LABEL marge=mom // Setup yamlDir := filepath.Join(tempdir, RandomString(12)) err := os.Mkdir(yamlDir, 0755) + Expect(err).To(BeNil(), "os.Mkdir "+yamlDir) err = writeYaml(testYAML, filepath.Join(yamlDir, "top.yaml")) Expect(err).To(BeNil()) diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 1a3b5f8df..fc939711f 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -4,8 +4,6 @@ import ( "bytes" "context" "fmt" - "github.com/containers/podman/v3/pkg/bindings" - "github.com/containers/podman/v3/pkg/bindings/play" "io/ioutil" "net" "net/url" @@ -17,6 +15,8 @@ import ( "time" "github.com/containers/podman/v3/libpod/define" + "github.com/containers/podman/v3/pkg/bindings" + "github.com/containers/podman/v3/pkg/bindings/play" "github.com/containers/podman/v3/pkg/util" . "github.com/containers/podman/v3/test/utils" "github.com/containers/storage/pkg/stringid" @@ -319,16 +319,16 @@ spec: image: {{ .Image }} name: {{ .Name }} imagePullPolicy: {{ .PullPolicy }} - {{- if or .CpuRequest .CpuLimit .MemoryRequest .MemoryLimit }} + {{- if or .CPURequest .CPULimit .MemoryRequest .MemoryLimit }} resources: - {{- if or .CpuRequest .MemoryRequest }} + {{- if or .CPURequest .MemoryRequest }} requests: - {{if .CpuRequest }}cpu: {{ .CpuRequest }}{{ end }} + {{if .CPURequest }}cpu: {{ .CPURequest }}{{ end }} {{if .MemoryRequest }}memory: {{ .MemoryRequest }}{{ end }} {{- end }} - {{- if or .CpuLimit .MemoryLimit }} + {{- if or .CPULimit .MemoryLimit }} limits: - {{if .CpuLimit }}cpu: {{ .CpuLimit }}{{ end }} + {{if .CPULimit }}cpu: {{ .CPULimit }}{{ end }} {{if .MemoryLimit }}memory: {{ .MemoryLimit }}{{ end }} {{- end }} {{- end }} @@ -479,16 +479,16 @@ spec: image: {{ .Image }} name: {{ .Name }} imagePullPolicy: {{ .PullPolicy }} - {{- if or .CpuRequest .CpuLimit .MemoryRequest .MemoryLimit }} + {{- if or .CPURequest .CPULimit .MemoryRequest .MemoryLimit }} resources: - {{- if or .CpuRequest .MemoryRequest }} + {{- if or .CPURequest .MemoryRequest }} requests: - {{if .CpuRequest }}cpu: {{ .CpuRequest }}{{ end }} + {{if .CPURequest }}cpu: {{ .CPURequest }}{{ end }} {{if .MemoryRequest }}memory: {{ .MemoryRequest }}{{ end }} {{- end }} - {{- if or .CpuLimit .MemoryLimit }} + {{- if or .CPULimit .MemoryLimit }} limits: - {{if .CpuLimit }}cpu: {{ .CpuLimit }}{{ end }} + {{if .CPULimit }}cpu: {{ .CPULimit }}{{ end }} {{if .MemoryLimit }}memory: {{ .MemoryLimit }}{{ end }} {{- end }} {{- end }} @@ -820,12 +820,6 @@ func getDeployment(options ...deploymentOption) *Deployment { type deploymentOption func(*Deployment) -func withDeploymentLabel(k, v string) deploymentOption { - return func(deployment *Deployment) { - deployment.Labels[k] = v - } -} - func withDeploymentAnnotation(k, v string) deploymentOption { return func(deployment *Deployment) { deployment.Annotations[k] = v @@ -866,8 +860,8 @@ type Ctr struct { Image string Cmd []string Arg []string - CpuRequest string - CpuLimit string + CPURequest string + CPULimit string MemoryRequest string MemoryLimit string SecurityContext bool @@ -947,15 +941,15 @@ func withImage(img string) ctrOption { } } -func withCpuRequest(request string) ctrOption { +func withCPURequest(request string) ctrOption { return func(c *Ctr) { - c.CpuRequest = request + c.CPURequest = request } } -func withCpuLimit(limit string) ctrOption { +func withCPULimit(limit string) ctrOption { return func(c *Ctr) { - c.CpuLimit = limit + c.CPULimit = limit } } @@ -1848,7 +1842,7 @@ var _ = Describe("Podman play kube", func() { It("podman play kube seccomp container level", func() { SkipIfRemote("podman-remote does not support --seccomp-profile-root flag") // expect play kube is expected to set a seccomp label if it's applied as an annotation - jsonFile, err := podmanTest.CreateSeccompJson(seccompPwdEPERM) + jsonFile, err := podmanTest.CreateSeccompJSON(seccompPwdEPERM) if err != nil { fmt.Println(err) Skip("Failed to prepare seccomp.json for test.") @@ -1861,7 +1855,7 @@ var _ = Describe("Podman play kube", func() { err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).To(BeNil()) - // CreateSeccompJson will put the profile into podmanTest.TempDir. Use --seccomp-profile-root to tell play kube where to look + // CreateSeccompJSON will put the profile into podmanTest.TempDir. Use --seccomp-profile-root to tell play kube where to look kube := podmanTest.Podman([]string{"play", "kube", "--seccomp-profile-root", podmanTest.TempDir, kubeYaml}) kube.WaitWithDefaultTimeout() Expect(kube).Should(Exit(0)) @@ -1875,7 +1869,7 @@ var _ = Describe("Podman play kube", func() { It("podman play kube seccomp pod level", func() { SkipIfRemote("podman-remote does not support --seccomp-profile-root flag") // expect play kube is expected to set a seccomp label if it's applied as an annotation - jsonFile, err := podmanTest.CreateSeccompJson(seccompPwdEPERM) + jsonFile, err := podmanTest.CreateSeccompJSON(seccompPwdEPERM) if err != nil { fmt.Println(err) Skip("Failed to prepare seccomp.json for test.") @@ -1888,7 +1882,7 @@ var _ = Describe("Podman play kube", func() { err = generateKubeYaml("pod", pod, kubeYaml) Expect(err).To(BeNil()) - // CreateSeccompJson will put the profile into podmanTest.TempDir. Use --seccomp-profile-root to tell play kube where to look + // CreateSeccompJSON will put the profile into podmanTest.TempDir. Use --seccomp-profile-root to tell play kube where to look kube := podmanTest.Podman([]string{"play", "kube", "--seccomp-profile-root", podmanTest.TempDir, kubeYaml}) kube.WaitWithDefaultTimeout() Expect(kube).Should(Exit(0)) @@ -2348,19 +2342,19 @@ VOLUME %s`, ALPINE, hostPathDir+"/") var ( numReplicas int32 = 3 - expectedCpuRequest string = "100m" - expectedCpuLimit string = "200m" + expectedCPURequest string = "100m" + expectedCPULimit string = "200m" expectedMemoryRequest string = "10000000" expectedMemoryLimit string = "20000000" ) - expectedCpuQuota := milliCPUToQuota(expectedCpuLimit) + expectedCPUQuota := milliCPUToQuota(expectedCPULimit) deployment := getDeployment( withReplicas(numReplicas), withPod(getPod(withCtr(getCtr( - withCpuRequest(expectedCpuRequest), - withCpuLimit(expectedCpuLimit), + withCPURequest(expectedCPURequest), + withCPULimit(expectedCPULimit), withMemoryRequest(expectedMemoryRequest), withMemoryLimit(expectedMemoryLimit), ))))) @@ -2372,6 +2366,7 @@ VOLUME %s`, ALPINE, hostPathDir+"/") Expect(kube).Should(Exit(0)) for _, pod := range getPodNamesInDeployment(deployment) { + pod := pod // copy into local scope inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&pod), "--format", ` CpuPeriod: {{ .HostConfig.CpuPeriod }} CpuQuota: {{ .HostConfig.CpuQuota }} @@ -2379,7 +2374,7 @@ Memory: {{ .HostConfig.Memory }} MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.OutputToString()).To(ContainSubstring(fmt.Sprintf("%s: %d", "CpuQuota", expectedCpuQuota))) + Expect(inspect.OutputToString()).To(ContainSubstring(fmt.Sprintf("%s: %d", "CpuQuota", expectedCPUQuota))) Expect(inspect.OutputToString()).To(ContainSubstring("MemoryReservation: " + expectedMemoryRequest)) Expect(inspect.OutputToString()).To(ContainSubstring("Memory: " + expectedMemoryLimit)) } @@ -2391,12 +2386,12 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) podmanTest.CgroupManager = "systemd" var ( - expectedCpuLimit string = "1" + expectedCPULimit string = "1" ) deployment := getDeployment( withPod(getPod(withCtr(getCtr( - withCpuLimit(expectedCpuLimit), + withCPULimit(expectedCPULimit), ))))) err := generateKubeYaml("deployment", deployment, kubeYaml) Expect(err).To(BeNil()) @@ -2406,6 +2401,7 @@ MemoryReservation: {{ .HostConfig.MemoryReservation }}`}) Expect(kube).Should(Exit(0)) for _, pod := range getPodNamesInDeployment(deployment) { + pod := pod // copy into local scope inspect := podmanTest.Podman([]string{"inspect", getCtrNameInPod(&pod), "--format", `{{ .HostConfig.CpuPeriod }}:{{ .HostConfig.CpuQuota }}`}) inspect.WaitWithDefaultTimeout() @@ -3054,6 +3050,7 @@ ENV OPENJ9_JAVA_OPTIONS=%q deployment := getDeployment(withPod(pod)) deploymentYaml, err := getKubeYaml("deployment", deployment) + Expect(err).To(BeNil(), "getKubeYaml(deployment)") yamls := []string{cmYaml, deploymentYaml} err = generateMultiDocKubeYaml(yamls, kubeYaml) Expect(err).To(BeNil()) diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go index a3dde3650..186688b93 100644 --- a/test/e2e/pod_create_test.go +++ b/test/e2e/pod_create_test.go @@ -173,7 +173,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/hosts"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), "12.34.56.78 test.example.com")).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring("12.34.56.78 test.example.com")) }) It("podman create pod with --add-host and no infra should fail", func() { @@ -193,7 +193,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("nameserver %s", server))).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring("nameserver %s", server)) }) It("podman create pod with DNS server set and no infra should fail", func() { @@ -214,7 +214,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("options %s", option))).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring(fmt.Sprintf("options %s", option))) }) It("podman create pod with DNS option set and no infra should fail", func() { @@ -235,7 +235,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "cat", "/etc/resolv.conf"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), fmt.Sprintf("search %s", search))).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring(fmt.Sprintf("search %s", search))) }) It("podman create pod with DNS search domain set and no infra should fail", func() { @@ -259,7 +259,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), ip)).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring(ip)) } }) @@ -302,7 +302,7 @@ var _ = Describe("Podman pod create", func() { podResolvConf := podmanTest.Podman([]string{"run", "--pod", name, "-ti", "--rm", ALPINE, "ip", "addr"}) podResolvConf.WaitWithDefaultTimeout() Expect(podResolvConf).Should(Exit(0)) - Expect(strings.Contains(podResolvConf.OutputToString(), mac)).To(BeTrue()) + Expect(podResolvConf.OutputToString()).To(ContainSubstring(mac)) } }) @@ -474,7 +474,7 @@ entrypoint ["/fromimage"] status1 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName}) status1.WaitWithDefaultTimeout() Expect(status1).Should(Exit(0)) - Expect(strings.Contains(status1.OutputToString(), "Created")).To(BeTrue()) + Expect(status1.OutputToString()).To(ContainSubstring("Created")) ctr1 := podmanTest.Podman([]string{"run", "--pod", podName, "-d", ALPINE, "top"}) ctr1.WaitWithDefaultTimeout() @@ -483,7 +483,7 @@ entrypoint ["/fromimage"] status2 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName}) status2.WaitWithDefaultTimeout() Expect(status2).Should(Exit(0)) - Expect(strings.Contains(status2.OutputToString(), "Running")).To(BeTrue()) + Expect(status2.OutputToString()).To(ContainSubstring("Running")) ctr2 := podmanTest.Podman([]string{"create", "--pod", podName, ALPINE, "top"}) ctr2.WaitWithDefaultTimeout() @@ -492,7 +492,7 @@ entrypoint ["/fromimage"] status3 := podmanTest.Podman([]string{"pod", "inspect", "--format", "{{ .State }}", podName}) status3.WaitWithDefaultTimeout() Expect(status3).Should(Exit(0)) - Expect(strings.Contains(status3.OutputToString(), "Degraded")).To(BeTrue()) + Expect(status3.OutputToString()).To(ContainSubstring("Degraded")) }) It("podman create with unsupported network options", func() { @@ -725,7 +725,7 @@ ENTRYPOINT ["sleep","99999"] session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) l := session.OutputToString() - Expect(strings.Contains(l, "1024")).To(BeTrue()) + Expect(l).To(ContainSubstring("1024")) m[l] = l } // check for no duplicates diff --git a/test/e2e/pod_inspect_test.go b/test/e2e/pod_inspect_test.go index 5728cf9b9..8a6f2a367 100644 --- a/test/e2e/pod_inspect_test.go +++ b/test/e2e/pod_inspect_test.go @@ -56,7 +56,7 @@ var _ = Describe("Podman pod inspect", func() { inspect := podmanTest.Podman([]string{"pod", "inspect", podid}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodToJSON() Expect(podData.ID).To(Equal(podid)) }) @@ -75,7 +75,7 @@ var _ = Describe("Podman pod inspect", func() { inspect := podmanTest.Podman([]string{"pod", "inspect", podName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) podData := inspect.InspectPodToJSON() // Let's get the last len(createCommand) items in the command. inspectCreateCommand := podData.CreateCommand diff --git a/test/e2e/pod_rm_test.go b/test/e2e/pod_rm_test.go index 7dc3dfa7f..d9b0761fa 100644 --- a/test/e2e/pod_rm_test.go +++ b/test/e2e/pod_rm_test.go @@ -132,11 +132,11 @@ var _ = Describe("Podman pod rm", func() { Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) fmt.Printf("Started container running in one pod") - num_pods := podmanTest.NumberOfPods() - Expect(num_pods).To(Equal(2)) + numPods := podmanTest.NumberOfPods() + Expect(numPods).To(Equal(2)) ps := podmanTest.Podman([]string{"pod", "ps"}) ps.WaitWithDefaultTimeout() - fmt.Printf("Current %d pod(s):\n%s\n", num_pods, ps.OutputToString()) + fmt.Printf("Current %d pod(s):\n%s\n", numPods, ps.OutputToString()) fmt.Printf("Removing all empty pods\n") result := podmanTest.Podman([]string{"pod", "rm", "-a"}) @@ -145,11 +145,11 @@ var _ = Describe("Podman pod rm", func() { foundExpectedError, _ := result.ErrorGrepString("cannot be removed") Expect(foundExpectedError).To(Equal(true)) - num_pods = podmanTest.NumberOfPods() + numPods = podmanTest.NumberOfPods() ps = podmanTest.Podman([]string{"pod", "ps"}) ps.WaitWithDefaultTimeout() - fmt.Printf("Final %d pod(s):\n%s\n", num_pods, ps.OutputToString()) - Expect(num_pods).To(Equal(1)) + fmt.Printf("Final %d pod(s):\n%s\n", numPods, ps.OutputToString()) + Expect(numPods).To(Equal(1)) // Confirm top container still running inside remaining pod Expect(podmanTest.NumberOfContainersRunning()).To(Equal(1)) }) diff --git a/test/e2e/pod_stats_test.go b/test/e2e/pod_stats_test.go index 5ec209034..bb145088e 100644 --- a/test/e2e/pod_stats_test.go +++ b/test/e2e/pod_stats_test.go @@ -149,7 +149,7 @@ var _ = Describe("Podman pod stats", func() { stats := podmanTest.Podman([]string{"pod", "stats", "--format", "json", "--no-stream", "-a"}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) It("podman pod stats with GO template", func() { _, ec, podid := podmanTest.CreatePod(nil) @@ -189,6 +189,6 @@ var _ = Describe("Podman pod stats", func() { stats := podmanTest.Podman([]string{"pod", "stats", "--format", "json", "--no-stream", podName}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) }) diff --git a/test/e2e/prune_test.go b/test/e2e/prune_test.go index 223fcc5b2..6b0081171 100644 --- a/test/e2e/prune_test.go +++ b/test/e2e/prune_test.go @@ -98,8 +98,7 @@ var _ = Describe("Podman prune", func() { session := podmanTest.Podman([]string{"images", "-a"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - hasNone, _ := session.GrepString("<none>") - Expect(hasNone).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("<none>"))) numImages := len(session.OutputToStringArray()) // Since there's no dangling image, none should be removed. @@ -125,8 +124,7 @@ var _ = Describe("Podman prune", func() { session = podmanTest.Podman([]string{"images", "-a"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - hasNone, _ = session.GrepString("<none>") - Expect(hasNone).To(BeTrue()) // ! we have dangling ones + Expect(session.OutputToString()).To(ContainSubstring("<none>")) numImages = len(session.OutputToStringArray()) // Since there's at least one dangling image, prune should @@ -135,7 +133,7 @@ var _ = Describe("Podman prune", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) numPrunedImages := len(session.OutputToStringArray()) - Expect(numPrunedImages >= 1).To(BeTrue()) + Expect(numPrunedImages).To(BeNumerically(">=", 1), "numPrunedImages") // Now make sure that exactly the number of pruned images has // been removed. @@ -189,11 +187,11 @@ var _ = Describe("Podman prune", func() { after := podmanTest.Podman([]string{"images", "-a"}) after.WaitWithDefaultTimeout() - Expect(none).Should(Exit(0)) - hasNoneAfter, result := none.GrepString("<none>") + Expect(after).Should(Exit(0)) + hasNoneAfter, result := after.GrepString("<none>") Expect(hasNoneAfter).To(BeTrue()) - Expect(len(after.OutputToStringArray()) > 1).To(BeTrue()) - Expect(len(result) > 0).To(BeTrue()) + Expect(len(after.OutputToStringArray())).To(BeNumerically(">", 1)) + Expect(len(result)).To(BeNumerically(">", 0)) }) It("podman image prune unused images", func() { diff --git a/test/e2e/ps_test.go b/test/e2e/ps_test.go index 666b70b09..3334250db 100644 --- a/test/e2e/ps_test.go +++ b/test/e2e/ps_test.go @@ -239,7 +239,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) }) It("podman ps namespace flag with json format", func() { @@ -249,7 +249,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) }) It("podman ps json format Created field is int64", func() { @@ -275,7 +275,7 @@ var _ = Describe("Podman ps", func() { result := podmanTest.Podman([]string{"ps", "-a", "--format", "json"}) result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) - Expect(result.IsJSONOutputValid()).To(BeTrue()) + Expect(result.OutputToString()).To(BeValidJSON()) // must contain "Status" match, StatusLine := result.GrepString(`Status`) Expect(match).To(BeTrue()) @@ -443,11 +443,10 @@ var _ = Describe("Podman ps", func() { // sanity check in case an oddly formatted size appears if len(matches1) < 2 || len(matches2) < 2 { return sortedArr[i] < sortedArr[j] - } else { - size1, _ := units.FromHumanSize(matches1[1]) - size2, _ := units.FromHumanSize(matches2[1]) - return size1 < size2 } + size1, _ := units.FromHumanSize(matches1[1]) + size2, _ := units.FromHumanSize(matches2[1]) + return size1 < size2 })).To(BeTrue()) }) diff --git a/test/e2e/pull_test.go b/test/e2e/pull_test.go index fdb1b0c57..b2474b223 100644 --- a/test/e2e/pull_test.go +++ b/test/e2e/pull_test.go @@ -279,7 +279,7 @@ var _ = Describe("Podman pull", func() { // Pulling a multi-image archive without further specifying // which image _must_ error out. Pulling is restricted to one // image. - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) expectedError := "Unexpected tar manifest.json: expected 1 item, got 2" @@ -288,31 +288,31 @@ var _ = Describe("Podman pull", func() { // Now pull _one_ image from a multi-image archive via the name // and index syntax. - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:@0")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:@0"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:example.com/empty:latest")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:example.com/empty:latest"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:@1")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:@1"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:example.com/empty/but:different")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:example.com/empty/but:different"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) // Now check for some errors. - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:foo.com/does/not/exist:latest")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:foo.com/does/not/exist:latest"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) expectedError = "Tag \"foo.com/does/not/exist:latest\" not found" found, _ = session.ErrorGrepString(expectedError) Expect(found).To(Equal(true)) - session = podmanTest.Podman([]string{"pull", fmt.Sprintf("docker-archive:./testdata/docker-two-images.tar.xz:@2")}) + session = podmanTest.Podman([]string{"pull", "docker-archive:./testdata/docker-two-images.tar.xz:@2"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) expectedError = "Invalid source index @2, only 2 manifest items available" @@ -391,7 +391,7 @@ var _ = Describe("Podman pull", func() { setup := podmanTest.Podman([]string{"images", ALPINE, "-q", "--no-trunc"}) setup.WaitWithDefaultTimeout() Expect(setup).Should(Exit(0)) - shortImageId := strings.Split(setup.OutputToString(), ":")[1] + shortImageID := strings.Split(setup.OutputToString(), ":")[1] rmi := podmanTest.Podman([]string{"rmi", ALPINE}) rmi.WaitWithDefaultTimeout() @@ -401,7 +401,7 @@ var _ = Describe("Podman pull", func() { pull.WaitWithDefaultTimeout() Expect(pull).Should(Exit(0)) - Expect(pull.OutputToString()).To(ContainSubstring(shortImageId)) + Expect(pull.OutputToString()).To(ContainSubstring(shortImageID)) }) It("podman pull check all tags", func() { diff --git a/test/e2e/push_test.go b/test/e2e/push_test.go index 7038a09e8..a3b5e31bb 100644 --- a/test/e2e/push_test.go +++ b/test/e2e/push_test.go @@ -2,12 +2,14 @@ package integration import ( "fmt" + "io/ioutil" "os" "path/filepath" "strings" "github.com/containers/podman/v3/pkg/rootless" . "github.com/containers/podman/v3/test/utils" + "github.com/containers/storage/pkg/archive" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/onsi/gomega/gexec" @@ -63,6 +65,36 @@ var _ = Describe("Podman push", func() { Expect(session).Should(Exit(0)) }) + It("podman push to oci with compression-format", func() { + SkipIfRemote("Remote push does not support dir transport") + bbdir := filepath.Join(podmanTest.TempDir, "busybox-oci") + session := podmanTest.Podman([]string{"push", "--compression-format=zstd", "--remove-signatures", ALPINE, + fmt.Sprintf("oci:%s", bbdir)}) + session.WaitWithDefaultTimeout() + Expect(session).Should(Exit(0)) + + foundZstdFile := false + + blobsDir := filepath.Join(bbdir, "blobs/sha256") + + blobs, err := ioutil.ReadDir(blobsDir) + Expect(err).To(BeNil()) + + for _, f := range blobs { + blobPath := filepath.Join(blobsDir, f.Name()) + + sourceFile, err := ioutil.ReadFile(blobPath) + Expect(err).To(BeNil()) + + compressionType := archive.DetectCompression(sourceFile) + if compressionType == archive.Zstd { + foundZstdFile = true + break + } + } + Expect(foundZstdFile).To(BeTrue()) + }) + It("podman push to local registry", func() { SkipIfRemote("Remote does not support --digestfile or --remove-signatures") if podmanTest.Host.Arch == "ppc64le" { diff --git a/test/e2e/restart_test.go b/test/e2e/restart_test.go index 6a61c1292..f85a74f47 100644 --- a/test/e2e/restart_test.go +++ b/test/e2e/restart_test.go @@ -154,8 +154,8 @@ var _ = Describe("Podman restart", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) timeSince := time.Since(startTime) - Expect(timeSince < 10*time.Second).To(BeTrue()) - Expect(timeSince > 2*time.Second).To(BeTrue()) + Expect(timeSince).To(BeNumerically("<", 10*time.Second)) + Expect(timeSince).To(BeNumerically(">", 2*time.Second)) }) It("Podman restart --all", func() { diff --git a/test/e2e/rmi_test.go b/test/e2e/rmi_test.go index 196d8879d..2c2a9688e 100644 --- a/test/e2e/rmi_test.go +++ b/test/e2e/rmi_test.go @@ -97,19 +97,19 @@ var _ = Describe("Podman rmi", func() { setup := podmanTest.Podman([]string{"images", "-q", cirros}) setup.WaitWithDefaultTimeout() Expect(setup).Should(Exit(0)) - cirrosId := setup.OutputToString() + cirrosID := setup.OutputToString() session := podmanTest.Podman([]string{"tag", "cirros", "foo:bar", "foo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) // Trying without --force should fail - result := podmanTest.Podman([]string{"rmi", cirrosId}) + result := podmanTest.Podman([]string{"rmi", cirrosID}) result.WaitWithDefaultTimeout() Expect(result).To(ExitWithError()) // With --force it should work - resultForce := podmanTest.Podman([]string{"rmi", "-f", cirrosId}) + resultForce := podmanTest.Podman([]string{"rmi", "-f", cirrosID}) resultForce.WaitWithDefaultTimeout() Expect(resultForce).Should(Exit(0)) }) @@ -276,8 +276,7 @@ RUN find $LOCAL session := podmanTest.Podman([]string{"image", "rm"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(125)) - match, _ := session.ErrorGrepString("image name or ID must be specified") - Expect(match).To(BeTrue()) + Expect(session.ErrorToString()).To(ContainSubstring("image name or ID must be specified")) }) It("podman image rm - concurrent with shared layers", func() { diff --git a/test/e2e/run_dns_test.go b/test/e2e/run_dns_test.go index beb6390e0..8b6d535e5 100644 --- a/test/e2e/run_dns_test.go +++ b/test/e2e/run_dns_test.go @@ -44,7 +44,7 @@ var _ = Describe("Podman run dns", func() { session := podmanTest.Podman([]string{"run", "--dns-search=.", ALPINE, "cat", "/etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputStartsWith("search")).To(BeFalse()) + Expect(session.OutputToStringArray()).To(Not(ContainElement(HavePrefix("search")))) }) It("podman run add bad dns server", func() { diff --git a/test/e2e/run_entrypoint_test.go b/test/e2e/run_entrypoint_test.go index f500a3c7c..29f76bad1 100644 --- a/test/e2e/run_entrypoint_test.go +++ b/test/e2e/run_entrypoint_test.go @@ -129,6 +129,6 @@ ENTRYPOINT ["grep", "Alpine", "/etc/os-release"] session := podmanTest.Podman([]string{"run", "--entrypoint=uname", "foobar.com/entrypoint:latest", "-r"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputStartsWith("Linux")).To(BeFalse()) + Expect(session.OutputToStringArray()).To(Not(ContainElement(HavePrefix("Linux")))) }) }) diff --git a/test/e2e/run_networking_test.go b/test/e2e/run_networking_test.go index e2004c8e0..22ec27346 100644 --- a/test/e2e/run_networking_test.go +++ b/test/e2e/run_networking_test.go @@ -551,8 +551,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "printenv", "HOSTNAME"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString(hostname) - Expect(match).Should(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring(hostname))) }) It("podman run --net host hostname test", func() { @@ -758,7 +757,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) run := podmanTest.Podman([]string{"run", "--net=host", "--hostname", hostname, ALPINE, "hostname"}) run.WaitWithDefaultTimeout() Expect(run).Should(Exit(0)) - Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) + Expect(run.OutputToString()).To(ContainSubstring(hostname)) }) It("podman run with --net=none sets hostname", func() { @@ -766,7 +765,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "hostname"}) run.WaitWithDefaultTimeout() Expect(run).Should(Exit(0)) - Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) + Expect(run.OutputToString()).To(ContainSubstring(hostname)) }) It("podman run with --net=none adds hostname to /etc/hosts", func() { @@ -774,7 +773,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) run := podmanTest.Podman([]string{"run", "--net=none", "--hostname", hostname, ALPINE, "cat", "/etc/hosts"}) run.WaitWithDefaultTimeout() Expect(run).Should(Exit(0)) - Expect(strings.Contains(run.OutputToString(), hostname)).To(BeTrue()) + Expect(run.OutputToString()).To(ContainSubstring(hostname)) }) It("podman run with pod does not add extra 127 entry to /etc/hosts", func() { @@ -789,7 +788,7 @@ EXPOSE 2004-2005/tcp`, ALPINE) Expect(run.OutputToString()).ToNot(ContainSubstring("127.0.0.1 %s", hostname)) }) - ping_test := func(netns string) { + pingTest := func(netns string) { hostname := "testctr" run := podmanTest.Podman([]string{"run", netns, "--hostname", hostname, ALPINE, "ping", "-c", "1", hostname}) run.WaitWithDefaultTimeout() @@ -801,11 +800,11 @@ EXPOSE 2004-2005/tcp`, ALPINE) } It("podman attempt to ping container name and hostname --net=none", func() { - ping_test("--net=none") + pingTest("--net=none") }) It("podman attempt to ping container name and hostname --net=private", func() { - ping_test("--net=private") + pingTest("--net=private") }) It("podman run check dnsname plugin", func() { @@ -866,7 +865,6 @@ EXPOSE 2004-2005/tcp`, ALPINE) inspectOut := podmanTest.InspectContainer(ctrName) Expect(len(inspectOut)).To(Equal(1)) Expect(len(inspectOut[0].NetworkSettings.Networks)).To(Equal(1)) - _, ok := inspectOut[0].NetworkSettings.Networks["podman"] - Expect(ok).To(BeTrue()) + Expect(inspectOut[0].NetworkSettings.Networks).To(HaveKey("podman")) }) }) diff --git a/test/e2e/run_passwd_test.go b/test/e2e/run_passwd_test.go index 05cdc7d80..6d1d26914 100644 --- a/test/e2e/run_passwd_test.go +++ b/test/e2e/run_passwd_test.go @@ -38,20 +38,20 @@ var _ = Describe("Podman run passwd", func() { session := podmanTest.Podman([]string{"run", "--read-only", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("passwd")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("passwd"))) }) It("podman run user specified in container", func() { session := podmanTest.Podman([]string{"run", "--read-only", "-u", "bin", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("passwd")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("passwd"))) }) It("podman run UID specified in container", func() { session := podmanTest.Podman([]string{"run", "--read-only", "-u", "2:1", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("passwd")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("passwd"))) }) It("podman run UID not specified in container", func() { @@ -77,14 +77,14 @@ USER 1000`, ALPINE) session := podmanTest.Podman([]string{"run", "--read-only", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("/etc/group")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("/etc/group"))) }) It("podman run group specified in container", func() { session := podmanTest.Podman([]string{"run", "--read-only", "-u", "root:bin", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("/etc/group")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("/etc/group"))) }) It("podman run non-numeric group not specified in container", func() { @@ -97,7 +97,7 @@ USER 1000`, ALPINE) session := podmanTest.Podman([]string{"run", "--read-only", "-u", "root:11", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("/etc/group")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("/etc/group"))) }) It("podman run numeric group not specified in container", func() { diff --git a/test/e2e/run_privileged_test.go b/test/e2e/run_privileged_test.go index d793a01f8..f1084a3d2 100644 --- a/test/e2e/run_privileged_test.go +++ b/test/e2e/run_privileged_test.go @@ -21,18 +21,18 @@ func containerCapMatchesHost(ctrCap string, hostCap string) { if isRootless() { return } - ctrCap_n, err := strconv.ParseUint(ctrCap, 16, 64) + ctrCapN, err := strconv.ParseUint(ctrCap, 16, 64) Expect(err).NotTo(HaveOccurred(), "Error parsing %q as hex", ctrCap) - hostCap_n, err := strconv.ParseUint(hostCap, 16, 64) + hostCapN, err := strconv.ParseUint(hostCap, 16, 64) Expect(err).NotTo(HaveOccurred(), "Error parsing %q as hex", hostCap) // host caps can never be zero (except rootless). // and host caps must always be a superset (inclusive) of container - Expect(hostCap_n).To(BeNumerically(">", 0), "host cap %q should be nonzero", hostCap) - Expect(hostCap_n).To(BeNumerically(">=", ctrCap_n), "host cap %q should never be less than container cap %q", hostCap, ctrCap) - hostCap_masked := hostCap_n & (1<<len(capability.List()) - 1) - Expect(ctrCap_n).To(Equal(hostCap_masked), "container cap %q is not a subset of host cap %q", ctrCap, hostCap) + Expect(hostCapN).To(BeNumerically(">", 0), "host cap %q should be nonzero", hostCap) + Expect(hostCapN).To(BeNumerically(">=", ctrCapN), "host cap %q should never be less than container cap %q", hostCap, ctrCap) + hostCapMasked := hostCapN & (1<<len(capability.List()) - 1) + Expect(ctrCapN).To(Equal(hostCapMasked), "container cap %q is not a subset of host cap %q", ctrCap, hostCap) } var _ = Describe("Podman privileged container tests", func() { @@ -63,9 +63,7 @@ var _ = Describe("Podman privileged container tests", func() { session := podmanTest.Podman([]string{"run", "--privileged", BB, "mount"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - ok, lines := session.GrepString("sysfs") - Expect(ok).To(BeTrue()) - Expect(lines[0]).To(ContainSubstring("sysfs (rw,")) + Expect(session.OutputToString()).To(ContainSubstring("sysfs (rw,")) }) It("podman privileged CapEff", func() { diff --git a/test/e2e/run_selinux_test.go b/test/e2e/run_selinux_test.go index cf63760cc..a6672d45e 100644 --- a/test/e2e/run_selinux_test.go +++ b/test/e2e/run_selinux_test.go @@ -320,7 +320,7 @@ var _ = Describe("Podman run", func() { }) It("podman test init labels", func() { - session := podmanTest.Podman([]string{"create", ubi_init, "/sbin/init"}) + session := podmanTest.Podman([]string{"create", UBI_INIT, "/sbin/init"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) cid := session.OutputToString() diff --git a/test/e2e/run_signal_test.go b/test/e2e/run_signal_test.go index 49f456366..6bb325155 100644 --- a/test/e2e/run_signal_test.go +++ b/test/e2e/run_signal_test.go @@ -116,8 +116,7 @@ var _ = Describe("Podman run with --sig-proxy", func() { } session, pid := podmanTest.PodmanPID([]string{"run", "--name", "test2", "--sig-proxy=false", fedoraMinimal, "bash", "-c", sigCatch2}) - ok := WaitForContainer(podmanTest) - Expect(ok).To(BeTrue()) + Expect(WaitForContainer(podmanTest)).To(BeTrue(), "WaitForContainer()") // Kill with given signal // Should be no output, SIGPOLL is usually ignored @@ -132,8 +131,7 @@ var _ = Describe("Podman run with --sig-proxy", func() { session.WaitWithDefaultTimeout() Expect(session).To(ExitWithError()) - ok, _ = session.GrepString("Received") - Expect(ok).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("Received"))) }) }) diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go index aa9037e56..3d4c1240e 100644 --- a/test/e2e/run_test.go +++ b/test/e2e/run_test.go @@ -318,7 +318,7 @@ var _ = Describe("Podman run", func() { forbidGetCWDSeccompProfile := func() string { in := []byte(`{"defaultAction":"SCMP_ACT_ALLOW","syscalls":[{"name":"getcwd","action":"SCMP_ACT_ERRNO"}]}`) - jsonFile, err := podmanTest.CreateSeccompJson(in) + jsonFile, err := podmanTest.CreateSeccompJSON(in) if err != nil { fmt.Println(err) Skip("Failed to prepare seccomp.json for test.") @@ -871,7 +871,7 @@ USER bin`, BB) session := podmanTest.Podman([]string{"run", "--rm", ALPINE, "id"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.LineInOutputContains("27(video),777,65533(nogroup)")).To(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("27(video),777,65533(nogroup)"))) }) It("podman run with group-add", func() { @@ -1151,8 +1151,7 @@ USER mail`, BB) session := podmanTest.Podman([]string{"run", "--volume", vol1 + ":/myvol1:z", "--volume", vol2 + ":/myvol2:z", fedoraMinimal, "findmnt", "-o", "TARGET,PROPAGATION"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - match, _ := session.GrepString("shared") - Expect(match).Should(BeFalse()) + Expect(session.OutputToString()).To(Not(ContainSubstring("shared"))) }) It("podman run findmnt shared", func() { @@ -1518,7 +1517,7 @@ USER mail`, BB) session := podmanTest.Podman([]string{"run", "-t", "-i", "--group-add", groupName, "--privileged", fedoraMinimal, "groups"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(strings.Contains(session.OutputToString(), groupName)).To(BeTrue()) + Expect(session.OutputToString()).To(ContainSubstring(groupName)) }) It("podman run --tz", func() { diff --git a/test/e2e/run_userns_test.go b/test/e2e/run_userns_test.go index 9b981ef72..50f8087f1 100644 --- a/test/e2e/run_userns_test.go +++ b/test/e2e/run_userns_test.go @@ -153,7 +153,7 @@ var _ = Describe("Podman UserNS support", func() { session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) l := session.OutputToString() - Expect(strings.Contains(l, "1024")).To(BeTrue()) + Expect(l).To(ContainSubstring("1024")) m[l] = l } // check for no duplicates diff --git a/test/e2e/run_volume_test.go b/test/e2e/run_volume_test.go index 967cf4a7c..74aa69c96 100644 --- a/test/e2e/run_volume_test.go +++ b/test/e2e/run_volume_test.go @@ -103,10 +103,8 @@ var _ = Describe("Podman run with volumes", func() { session = podmanTest.Podman([]string{"run", "--rm", "--mount", mount + ",consistency=delegated,shared", ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - found, matches := session.GrepString(dest) - Expect(found).Should(BeTrue()) - Expect(matches[0]).To(ContainSubstring("rw")) - Expect(matches[0]).To(ContainSubstring("shared")) + Expect(session.OutputToString()).To(ContainSubstring("rw")) + Expect(session.OutputToString()).To(ContainSubstring("shared")) session = podmanTest.Podman([]string{"run", "--rm", "--mount", "type=tmpfs,target=" + dest, ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() @@ -151,6 +149,7 @@ var _ = Describe("Podman run with volumes", func() { Expect(err).To(BeNil()) testFile := filepath.Join(mountPath, "test1") f, err := os.Create(testFile) + Expect(err).To(BeNil(), "os.Create(testfile)") f.Close() Expect(err).To(BeNil()) session := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/data", mountPath), redis, "ls", "/data/test1"}) @@ -194,20 +193,18 @@ var _ = Describe("Podman run with volumes", func() { session := podmanTest.Podman([]string{"run", "--rm", "-v", mountPath + ":" + dest + ":suid,dev,exec", ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - found, matches := session.GrepString(dest) - Expect(found).Should(BeTrue()) - Expect(matches[0]).To(Not(ContainSubstring("noexec"))) - Expect(matches[0]).To(Not(ContainSubstring("nodev"))) - Expect(matches[0]).To(Not(ContainSubstring("nosuid"))) + output := session.OutputToString() + Expect(output).To(Not(ContainSubstring("noexec"))) + Expect(output).To(Not(ContainSubstring("nodev"))) + Expect(output).To(Not(ContainSubstring("nosuid"))) session = podmanTest.Podman([]string{"run", "--rm", "--tmpfs", dest + ":suid,dev,exec", ALPINE, "grep", dest, "/proc/self/mountinfo"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - found, matches = session.GrepString(dest) - Expect(found).Should(BeTrue()) - Expect(matches[0]).To(Not(ContainSubstring("noexec"))) - Expect(matches[0]).To(Not(ContainSubstring("nodev"))) - Expect(matches[0]).To(Not(ContainSubstring("nosuid"))) + output = session.OutputToString() + Expect(output).To(Not(ContainSubstring("noexec"))) + Expect(output).To(Not(ContainSubstring("nodev"))) + Expect(output).To(Not(ContainSubstring("nosuid"))) }) // Container should start when workdir is overlay volume @@ -286,7 +283,7 @@ var _ = Describe("Podman run with volumes", func() { os.Stderr.Sync() mountOut1 := strings.Join(strings.Fields(string(mountCmd1.Out.Contents())), " ") fmt.Printf("Output: %s", mountOut1) - Expect(strings.Contains(mountOut1, volName)).To(BeFalse()) + Expect(mountOut1).To(Not(ContainSubstring(volName))) ctrName := "testctr" podmanSession := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, "-v", fmt.Sprintf("%s:/testvol", volName), ALPINE, "top"}) @@ -302,7 +299,7 @@ var _ = Describe("Podman run with volumes", func() { os.Stderr.Sync() mountOut2 := strings.Join(strings.Fields(string(mountCmd2.Out.Contents())), " ") fmt.Printf("Output: %s", mountOut2) - Expect(strings.Contains(mountOut2, volName)).To(BeTrue()) + Expect(mountOut2).To(ContainSubstring(volName)) // Stop the container to unmount podmanStopSession := podmanTest.Podman([]string{"stop", "--time", "0", ctrName}) @@ -323,7 +320,7 @@ var _ = Describe("Podman run with volumes", func() { os.Stderr.Sync() mountOut3 := strings.Join(strings.Fields(string(mountCmd3.Out.Contents())), " ") fmt.Printf("Output: %s", mountOut3) - Expect(strings.Contains(mountOut3, volName)).To(BeFalse()) + Expect(mountOut3).To(Not(ContainSubstring(volName))) }) It("podman named volume copyup", func() { @@ -515,7 +512,7 @@ RUN sh -c "cd /etc/apk && ln -s ../../testfile"`, ALPINE) Expect(runLs).Should(Exit(0)) outputArr := runLs.OutputToStringArray() Expect(len(outputArr)).To(Equal(1)) - Expect(strings.Contains(outputArr[0], fileName)).To(BeTrue()) + Expect(outputArr[0]).To(ContainSubstring(fileName)) }) It("Podman mount over image volume with trailing /", func() { @@ -550,6 +547,7 @@ VOLUME /test/`, ALPINE) os.Mkdir(mountPath, 0755) testFile := filepath.Join(mountPath, "test1") f, err := os.Create(testFile) + Expect(err).To(BeNil(), "os.Create "+testFile) f.Close() // Make sure host directory gets mounted in to container as overlay @@ -750,7 +748,7 @@ USER testuser`, fedoraMinimal) test1 := podmanTest.Podman([]string{"run", "-v", "testvol1:/test", imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"}) test1.WaitWithDefaultTimeout() Expect(test1).Should(Exit(0)) - Expect(strings.Contains(test1.OutputToString(), testString)).To(BeTrue()) + Expect(test1.OutputToString()).To(ContainSubstring(testString)) volName := "testvol2" vol := podmanTest.Podman([]string{"volume", "create", volName}) @@ -760,7 +758,7 @@ USER testuser`, fedoraMinimal) test2 := podmanTest.Podman([]string{"run", "-v", fmt.Sprintf("%s:/test", volName), imgName, "bash", "-c", "ls -al /test | grep -v root | grep -v total"}) test2.WaitWithDefaultTimeout() Expect(test2).Should(Exit(0)) - Expect(strings.Contains(test2.OutputToString(), testString)).To(BeTrue()) + Expect(test2.OutputToString()).To(ContainSubstring(testString)) }) diff --git a/test/e2e/runlabel_test.go b/test/e2e/runlabel_test.go index 656eaaceb..b7b27dc14 100644 --- a/test/e2e/runlabel_test.go +++ b/test/e2e/runlabel_test.go @@ -94,18 +94,19 @@ var _ = Describe("podman container runlabel", func() { result.WaitWithDefaultTimeout() Expect(result).To(ExitWithError()) // should not panic when label missing the value or don't have the label - Expect(result.LineInOutputContains("panic")).NotTo(BeTrue()) + Expect(result.OutputToString()).To(Not(ContainSubstring("panic"))) }) It("podman container runlabel bogus label in remote image should result in non-zero exit", func() { result := podmanTest.Podman([]string{"container", "runlabel", "RUN", "docker.io/library/ubuntu:latest"}) result.WaitWithDefaultTimeout() Expect(result).To(ExitWithError()) // should not panic when label missing the value or don't have the label - Expect(result.LineInOutputContains("panic")).NotTo(BeTrue()) + Expect(result.OutputToString()).To(Not(ContainSubstring("panic"))) }) It("podman container runlabel global options", func() { - Skip("Test nonfunctional for podman-in-podman testing") + fmt.Printf("FIXME: for lint. Remove when you fix this test: %s", GlobalDockerfile) + Skip("FIXME: $GLOBAL_OPTS does not work at all, #12436") image := "podman-global-test:ls" podmanTest.BuildImage(GlobalDockerfile, image, "false") result := podmanTest.Podman([]string{"--syslog", "--log-level", "debug", "container", "runlabel", "RUN", image}) diff --git a/test/e2e/search_test.go b/test/e2e/search_test.go index 2ea88eb5e..c67ef7ed2 100644 --- a/test/e2e/search_test.go +++ b/test/e2e/search_test.go @@ -6,7 +6,6 @@ import ( "fmt" "io/ioutil" "os" - "regexp" "strconv" "text/template" @@ -107,10 +106,8 @@ registries = ['{{.Host}}:{{.Port}}']` search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) output := string(search.Out.Contents()) - match, _ := regexp.MatchString(`(?m)NAME\s+DESCRIPTION$`, output) - Expect(match).To(BeTrue()) - match, _ = regexp.MatchString(`(?m)quay.io/libpod/whalesay\s+Static image used for automated testing.+$`, output) - Expect(match).To(BeTrue()) + Expect(output).To(MatchRegexp(`(?m)NAME\s+DESCRIPTION$`)) + Expect(output).To(MatchRegexp(`(?m)quay.io/libpod/whalesay\s+Static image used for automated testing.+$`)) }) It("podman search image with --compatible", func() { @@ -118,8 +115,7 @@ registries = ['{{.Host}}:{{.Port}}']` search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) output := string(search.Out.Contents()) - match, _ := regexp.MatchString(`(?m)NAME\s+DESCRIPTION\s+STARS\s+OFFICIAL\s+AUTOMATED$`, output) - Expect(match).To(BeTrue()) + Expect(output).To(MatchRegexp(`(?m)NAME\s+DESCRIPTION\s+STARS\s+OFFICIAL\s+AUTOMATED$`)) }) It("podman search format flag", func() { @@ -134,7 +130,7 @@ registries = ['{{.Host}}:{{.Port}}']` search := podmanTest.Podman([]string{"search", "--format", "json", "alpine"}) search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) - Expect(search.IsJSONOutputValid()).To(BeTrue()) + Expect(search.OutputToString()).To(BeValidJSON()) Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine")) // Test for https://github.com/containers/podman/issues/11894 @@ -151,7 +147,7 @@ registries = ['{{.Host}}:{{.Port}}']` search := podmanTest.Podman([]string{"search", "--list-tags", "--format", "json", "alpine"}) search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) - Expect(search.IsJSONOutputValid()).To(BeTrue()) + Expect(search.OutputToString()).To(BeValidJSON()) Expect(search.OutputToString()).To(ContainSubstring("docker.io/library/alpine")) Expect(search.OutputToString()).To(ContainSubstring("3.10")) Expect(search.OutputToString()).To(ContainSubstring("2.7")) @@ -354,8 +350,7 @@ registries = ['{{.Host}}:{{.Port}}']` Expect(search).Should(Exit(125)) Expect(search.OutputToString()).Should(BeEmpty()) - match, _ := search.ErrorGrepString("error") - Expect(match).Should(BeTrue()) + Expect(search.ErrorToString()).To(ContainSubstring("error")) // cleanup resetRegistriesConfigEnv() @@ -397,8 +392,7 @@ registries = ['{{.Host}}:{{.Port}}']` Expect(search).Should(Exit(125)) Expect(search.OutputToString()).Should(BeEmpty()) - match, _ := search.ErrorGrepString("error") - Expect(match).Should(BeTrue()) + Expect(search.ErrorToString()).To(ContainSubstring("error")) // cleanup resetRegistriesConfigEnv() @@ -451,8 +445,7 @@ registries = ['{{.Host}}:{{.Port}}']` Expect(search).Should(Exit(125)) Expect(search.OutputToString()).Should(BeEmpty()) - match, _ := search.ErrorGrepString("error") - Expect(match).Should(BeTrue()) + Expect(search.ErrorToString()).To(ContainSubstring("error")) // cleanup resetRegistriesConfigEnv() @@ -474,7 +467,7 @@ registries = ['{{.Host}}:{{.Port}}']` search = podmanTest.Podman([]string{"search", "registry.redhat.io/*openshift*"}) search.WaitWithDefaultTimeout() Expect(search).Should(Exit(0)) - Expect(len(search.OutputToStringArray()) > 1).To(BeTrue()) + Expect(len(search.OutputToStringArray())).To(BeNumerically(">", 1)) }) It("podman search repository tags", func() { @@ -494,7 +487,7 @@ registries = ['{{.Host}}:{{.Port}}']` search = podmanTest.Podman([]string{"search", "--list-tags", "docker.io/library/"}) search.WaitWithDefaultTimeout() - Expect(len(search.OutputToStringArray()) == 0).To(BeTrue()) + Expect(search.OutputToStringArray()).To(BeEmpty()) }) It("podman search with limit over 100", func() { diff --git a/test/e2e/secret_test.go b/test/e2e/secret_test.go index 8bbc889d7..758ed7edc 100644 --- a/test/e2e/secret_test.go +++ b/test/e2e/secret_test.go @@ -78,7 +78,7 @@ var _ = Describe("Podman secret", func() { inspect := podmanTest.Podman([]string{"secret", "inspect", secrID}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) }) It("podman secret inspect with --format", func() { @@ -115,7 +115,7 @@ var _ = Describe("Podman secret", func() { inspect := podmanTest.Podman([]string{"secret", "inspect", secrID, secrID2}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(inspect.IsJSONOutputValid()).To(BeTrue()) + Expect(inspect.OutputToString()).To(BeValidJSON()) }) It("podman secret inspect bogus", func() { @@ -208,7 +208,6 @@ var _ = Describe("Podman secret", func() { // no env variable set, should fail session := podmanTest.Podman([]string{"secret", "create", "--env", "a", "MYENVVAR"}) session.WaitWithDefaultTimeout() - secrID := session.OutputToString() Expect(session).To(ExitWithError()) os.Setenv("MYENVVAR", "somedata") @@ -218,7 +217,7 @@ var _ = Describe("Podman secret", func() { session = podmanTest.Podman([]string{"secret", "create", "--env", "a", "MYENVVAR"}) session.WaitWithDefaultTimeout() - secrID = session.OutputToString() + secrID := session.OutputToString() Expect(session).Should(Exit(0)) inspect := podmanTest.Podman([]string{"secret", "inspect", "--format", "{{.ID}}", secrID}) diff --git a/test/e2e/stats_test.go b/test/e2e/stats_test.go index c0d56fdbc..a58e2485c 100644 --- a/test/e2e/stats_test.go +++ b/test/e2e/stats_test.go @@ -148,7 +148,7 @@ var _ = Describe("Podman stats", func() { stats := podmanTest.Podman([]string{"stats", "--all", "--no-stream", "--format", "json"}) stats.WaitWithDefaultTimeout() Expect(stats).Should(Exit(0)) - Expect(stats.IsJSONOutputValid()).To(BeTrue()) + Expect(stats.OutputToString()).To(BeValidJSON()) }) It("podman stats on a container with no net ns", func() { diff --git a/test/e2e/systemd_test.go b/test/e2e/systemd_test.go index 32c2cd1b8..bbbec1648 100644 --- a/test/e2e/systemd_test.go +++ b/test/e2e/systemd_test.go @@ -35,7 +35,7 @@ ExecStart=/usr/bin/podman start -a redis ExecStop=/usr/bin/podman stop -t 10 redis KillMode=process [Install] -WantedBy=multi-user.target +WantedBy=default.target ` }) @@ -50,8 +50,8 @@ WantedBy=multi-user.target SkipIfRootless("rootless can not write to /etc") SkipIfContainerized("test does not have systemd as pid 1") - sys_file := ioutil.WriteFile("/etc/systemd/system/redis.service", []byte(systemdUnitFile), 0644) - Expect(sys_file).To(BeNil()) + sysFile := ioutil.WriteFile("/etc/systemd/system/redis.service", []byte(systemdUnitFile), 0644) + Expect(sysFile).To(BeNil()) defer func() { stop := SystemExec("bash", []string{"-c", "systemctl stop redis"}) os.Remove("/etc/systemd/system/redis.service") @@ -78,7 +78,7 @@ WantedBy=multi-user.target It("podman run container with systemd PID1", func() { ctrName := "testSystemd" - run := podmanTest.Podman([]string{"run", "--name", ctrName, "-t", "-i", "-d", ubi_init, "/sbin/init"}) + run := podmanTest.Podman([]string{"run", "--name", ctrName, "-t", "-i", "-d", UBI_INIT, "/sbin/init"}) run.WaitWithDefaultTimeout() Expect(run).Should(Exit(0)) @@ -93,7 +93,7 @@ WantedBy=multi-user.target systemctl := podmanTest.Podman([]string{"exec", "-t", "-i", ctrName, "systemctl", "status", "--no-pager"}) systemctl.WaitWithDefaultTimeout() Expect(systemctl).Should(Exit(0)) - Expect(strings.Contains(systemctl.OutputToString(), "State:")).To(BeTrue()) + Expect(systemctl.OutputToString()).To(ContainSubstring("State:")) result := podmanTest.Podman([]string{"inspect", ctrName}) result.WaitWithDefaultTimeout() @@ -118,7 +118,7 @@ WantedBy=multi-user.target It("podman create container with systemd entrypoint triggers systemd mode", func() { ctrName := "testCtr" - run := podmanTest.Podman([]string{"create", "--name", ctrName, "--entrypoint", "/sbin/init", ubi_init}) + run := podmanTest.Podman([]string{"create", "--name", ctrName, "--entrypoint", "/sbin/init", UBI_INIT}) run.WaitWithDefaultTimeout() Expect(run).Should(Exit(0)) diff --git a/test/e2e/toolbox_test.go b/test/e2e/toolbox_test.go index e1fe44675..40db5180a 100644 --- a/test/e2e/toolbox_test.go +++ b/test/e2e/toolbox_test.go @@ -66,9 +66,7 @@ var _ = Describe("Toolbox-specific testing", func() { }) It("podman run --dns=none - allows self-management of /etc/resolv.conf", func() { - var session *PodmanSessionIntegration - - session = podmanTest.Podman([]string{"run", "--dns", "none", ALPINE, "sh", "-c", + session := podmanTest.Podman([]string{"run", "--dns", "none", ALPINE, "sh", "-c", "rm -f /etc/resolv.conf; touch -d '1970-01-01 00:02:03' /etc/resolv.conf; stat -c %s:%Y /etc/resolv.conf"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -76,9 +74,7 @@ var _ = Describe("Toolbox-specific testing", func() { }) It("podman run --no-hosts - allows self-management of /etc/hosts", func() { - var session *PodmanSessionIntegration - - session = podmanTest.Podman([]string{"run", "--no-hosts", ALPINE, "sh", "-c", + session := podmanTest.Podman([]string{"run", "--no-hosts", ALPINE, "sh", "-c", "rm -f /etc/hosts; touch -d '1970-01-01 00:02:03' /etc/hosts; stat -c %s:%Y /etc/hosts"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) @@ -164,9 +160,7 @@ var _ = Describe("Toolbox-specific testing", func() { }) It("podman create --userns=keep-id --user root:root - entrypoint - entrypoint is executed as root", func() { - var session *PodmanSessionIntegration - - session = podmanTest.Podman([]string{"run", "--userns=keep-id", "--user", "root:root", ALPINE, + session := podmanTest.Podman([]string{"run", "--userns=keep-id", "--user", "root:root", ALPINE, "id"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) diff --git a/test/e2e/top_test.go b/test/e2e/top_test.go index 93c4f3f12..1a71ebf33 100644 --- a/test/e2e/top_test.go +++ b/test/e2e/top_test.go @@ -101,6 +101,11 @@ var _ = Describe("Podman top", func() { result.WaitWithDefaultTimeout() Expect(result).Should(Exit(0)) Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) + + result = podmanTest.Podman([]string{"top", session.OutputToString(), "ax -o args"}) + result.WaitWithDefaultTimeout() + Expect(result).Should(Exit(0)) + Expect(result.OutputToStringArray()).To(Equal([]string{"COMMAND", "top -d 2"})) }) It("podman top with comma-separated options", func() { diff --git a/test/e2e/trust_test.go b/test/e2e/trust_test.go index b591e1c02..9a0d57d7a 100644 --- a/test/e2e/trust_test.go +++ b/test/e2e/trust_test.go @@ -76,7 +76,7 @@ var _ = Describe("Podman trust", func() { session := podmanTest.Podman([]string{"image", "trust", "show", "--registrypath", filepath.Join(INTEGRATION_ROOT, "test"), "--policypath", filepath.Join(INTEGRATION_ROOT, "test/policy.json"), "--json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) var teststruct []map[string]string json.Unmarshal(session.Out.Contents(), &teststruct) Expect(len(teststruct)).To(Equal(3)) @@ -118,7 +118,7 @@ var _ = Describe("Podman trust", func() { Expect(session).Should(Exit(0)) contents, err := ioutil.ReadFile(filepath.Join(INTEGRATION_ROOT, "test/policy.json")) Expect(err).ShouldNot(HaveOccurred()) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) Expect(string(session.Out.Contents())).To(Equal(string(contents) + "\n")) }) }) diff --git a/test/e2e/volume_create_test.go b/test/e2e/volume_create_test.go index d1f769724..90a9bfb0b 100644 --- a/test/e2e/volume_create_test.go +++ b/test/e2e/volume_create_test.go @@ -97,13 +97,12 @@ var _ = Describe("Podman volume create", func() { session = podmanTest.Podman([]string{"volume", "create", "my_vol2"}) session.WaitWithDefaultTimeout() - volName = session.OutputToString() Expect(session).Should(Exit(0)) session = podmanTest.Podman([]string{"volume", "import", "my_vol2", "hello.tar"}) session.WaitWithDefaultTimeout() - volName = session.OutputToString() Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(Equal(""), "output of volume import") session = podmanTest.Podman([]string{"run", "--volume", "my_vol2:/data", ALPINE, "cat", "/data/test"}) session.WaitWithDefaultTimeout() diff --git a/test/e2e/volume_inspect_test.go b/test/e2e/volume_inspect_test.go index db95ba675..172063b90 100644 --- a/test/e2e/volume_inspect_test.go +++ b/test/e2e/volume_inspect_test.go @@ -2,7 +2,6 @@ package integration import ( "os" - "strings" . "github.com/containers/podman/v3/test/utils" . "github.com/onsi/ginkgo" @@ -43,7 +42,7 @@ var _ = Describe("Podman volume inspect", func() { session = podmanTest.Podman([]string{"volume", "inspect", volName}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman inspect volume with Go format", func() { @@ -86,6 +85,6 @@ var _ = Describe("Podman volume inspect", func() { inspect := podmanTest.Podman([]string{"volume", "inspect", volName}) inspect.WaitWithDefaultTimeout() Expect(inspect).Should(Exit(0)) - Expect(strings.Contains(inspect.OutputToString(), "tmpfs")).To(BeTrue()) + Expect(inspect.OutputToString()).To(ContainSubstring("tmpfs")) }) }) diff --git a/test/e2e/volume_ls_test.go b/test/e2e/volume_ls_test.go index 6c4b22fa5..c1214366b 100644 --- a/test/e2e/volume_ls_test.go +++ b/test/e2e/volume_ls_test.go @@ -64,7 +64,7 @@ var _ = Describe("Podman volume ls", func() { session = podmanTest.Podman([]string{"volume", "ls", "--format", "json"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(session.IsJSONOutputValid()).To(BeTrue()) + Expect(session.OutputToString()).To(BeValidJSON()) }) It("podman ls volume with Go template", func() { diff --git a/test/e2e/volume_rm_test.go b/test/e2e/volume_rm_test.go index 0119e0f7a..a05c1b593 100644 --- a/test/e2e/volume_rm_test.go +++ b/test/e2e/volume_rm_test.go @@ -127,6 +127,6 @@ var _ = Describe("Podman volume rm", func() { session = podmanTest.Podman([]string{"volume", "ls"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - Expect(len(session.OutputToStringArray()) >= 2).To(BeTrue()) + Expect(len(session.OutputToStringArray())).To(BeNumerically(">=", 2)) }) }) diff --git a/test/python/docker/compat/test_containers.py b/test/python/docker/compat/test_containers.py index e6f7d992d..d14c09fc1 100644 --- a/test/python/docker/compat/test_containers.py +++ b/test/python/docker/compat/test_containers.py @@ -3,11 +3,13 @@ import subprocess import sys import time import unittest -from typing import IO, Optional +from typing import IO, Optional, List from docker import DockerClient, errors from docker.models.containers import Container from docker.models.images import Image +from docker.models.volumes import Volume +from docker.types import Mount from test.python.docker import Podman from test.python.docker.compat import common, constant @@ -207,9 +209,14 @@ class TestContainers(unittest.TestCase): def test_copy_to_container(self): ctr: Optional[Container] = None + vol: Optional[Volume] = None try: test_file_content = b"Hello World!" - ctr = self.client.containers.create(image="alpine", detach=True, command="top") + vol = self.client.volumes.create("test-volume") + ctr = self.client.containers.create(image="alpine", + detach=True, + command="top", + volumes=["test-volume:/test-volume-read-only:ro"]) ctr.start() buff: IO[bytes] = io.BytesIO() @@ -234,10 +241,16 @@ class TestContainers(unittest.TestCase): ret, out = ctr.exec_run(["cat", "/tmp/a.txt"]) self.assertEqual(ret, 0) self.assertEqual(out.rstrip(), test_file_content, "Content of copied file") + + buff.seek(0) + with self.assertRaises(errors.APIError): + ctr.put_archive("/test-volume-read-only/", buff) finally: if ctr is not None: ctr.stop() ctr.remove() + if vol is not None: + vol.remove(force=True) def test_mount_preexisting_dir(self): dockerfile = (B'FROM quay.io/libpod/alpine:latest\n' @@ -265,3 +278,25 @@ class TestContainers(unittest.TestCase): ctr.start() ret, out = ctr.exec_run(["stat", "/workspace/scratch/test"]) self.assertEqual(ret, 0, "Working directory created if it doesn't exist") + + def test_mount_rw_by_default(self): + ctr: Optional[Container] = None + vol: Optional[Volume] = None + try: + vol = self.client.volumes.create("test-volume") + ctr = self.client.containers.create(image="alpine", + detach=True, + command="top", + mounts=[Mount(target="/vol-mnt", + source="test-volume", + type='volume', + read_only=False)]) + ctr_inspect = self.client.api.inspect_container(ctr.id) + binds: List[str] = ctr_inspect["HostConfig"]["Binds"] + self.assertEqual(len(binds), 1) + self.assertEqual(binds[0], 'test-volume:/vol-mnt:rw,rprivate,nosuid,nodev,rbind') + finally: + if ctr is not None: + ctr.remove() + if vol is not None: + vol.remove(force=True) diff --git a/test/system/180-blkio.bats b/test/system/180-blkio.bats new file mode 100644 index 000000000..68449681a --- /dev/null +++ b/test/system/180-blkio.bats @@ -0,0 +1,69 @@ +#!/usr/bin/env bats -*- bats -*- +# +# podman blkio-related tests +# + +load helpers + +function teardown() { + lofile=${PODMAN_TMPDIR}/disk.img + if [ -f ${lofile} ]; then + run_podman '?' rm -t 0 --all --force + + while read path dev; do + if [[ "$path" == "$lofile" ]]; then + losetup -d $dev + fi + done < <(losetup -l --noheadings --output BACK-FILE,NAME) + + rm ${lofile} + fi + basic_teardown +} + +@test "podman run --blkio-weight-device" { + + skip_if_rootless "cannot create devices in rootless mode" + + # create loopback device + lofile=${PODMAN_TMPDIR}/disk.img + fallocate -l 1k ${lofile} + losetup -f ${lofile} + + run losetup -l --noheadings --output BACK-FILE,NAME,MAJ:MIN + is "$output" ".\+" "Empty output from losetup" + + lodevice=$(awk "\$1 == \"$lofile\" { print \$2 }" <<<"$output") + lomajmin=$(awk "\$1 == \"$lofile\" { print \$3 }" <<<"$output") + + is "$lodevice" ".\+" "Could not determine device for $lofile" + is "$lomajmin" ".\+" "Could not determine major/minor for $lofile" + + # use bfq io scheduler + run grep -w bfq /sys/block/$(basename ${lodevice})/queue/scheduler + if [ $status -ne 0 ]; then + skip "BFQ scheduler is not supported on the system" + fi + echo bfq > /sys/block/$(basename ${lodevice})/queue/scheduler + + # run podman + if is_cgroupsv2; then + if [ ! -f /sys/fs/cgroup/system.slice/io.bfq.weight ]; then + skip "Kernel does not support BFQ IO scheduler" + fi + run_podman run --device ${lodevice}:${lodevice} --blkio-weight-device ${lodevice}:123 --rm $IMAGE \ + /bin/sh -c "cat /sys/fs/cgroup/\$(sed -e 's/0:://' < /proc/self/cgroup)/io.bfq.weight" + is "${lines[1]}" "${lomajmin}\s\+123" + else + if [ ! -f /sys/fs/cgroup/blkio/system.slice/blkio.bfq.weight_device ]; then + skip "Kernel does not support BFQ IO scheduler" + fi + if [ $(podman_runtime) = "crun" ]; then + # As of crun 1.2, crun doesn't support blkio.bfq.weight_device + skip "crun doesn't support blkio.bfq.weight_device" + fi + run_podman run --device ${lodevice}:${lodevice} --blkio-weight-device ${lodevice}:123 --rm $IMAGE \ + /bin/sh -c "cat /sys/fs/cgroup/blkio/blkio.bfq.weight_device" + is "${lines[1]}" "${lomajmin}\s\+123" + fi +} diff --git a/test/system/250-systemd.bats b/test/system/250-systemd.bats index 4757f7643..56d36934d 100644 --- a/test/system/250-systemd.bats +++ b/test/system/250-systemd.bats @@ -34,6 +34,12 @@ function service_setup() { systemctl daemon-reload + # Also test enabling services (see #12438). + run systemctl enable "$SERVICE_NAME" + if [ $status -ne 0 ]; then + die "Error enabling systemd unit $SERVICE_NAME, output: $output" + fi + run systemctl start "$SERVICE_NAME" if [ $status -ne 0 ]; then die "Error starting systemd unit $SERVICE_NAME, output: $output" @@ -53,6 +59,11 @@ function service_cleanup() { die "Error stopping systemd unit $SERVICE_NAME, output: $output" fi + run systemctl disable "$SERVICE_NAME" + if [ $status -ne 0 ]; then + die "Error disbling systemd unit $SERVICE_NAME, output: $output" + fi + if [[ -z "$status" ]]; then run systemctl is-active "$SERVICE_NAME" if [ $status -ne 0 ]; then diff --git a/test/system/255-auto-update.bats b/test/system/255-auto-update.bats index 99211f304..7540270bd 100644 --- a/test/system/255-auto-update.bats +++ b/test/system/255-auto-update.bats @@ -366,7 +366,7 @@ Type=oneshot ExecStart=/usr/bin/podman auto-update [Install] -WantedBy=multi-user.target default.target +WantedBy=default.target EOF echo "podman-auto-update-$cname" >> $SNAME_FILE diff --git a/test/testvol/main.go b/test/testvol/main.go index a0f58348b..d15bf00cd 100644 --- a/test/testvol/main.go +++ b/test/testvol/main.go @@ -129,8 +129,8 @@ func (d *DirDriver) Capabilities() *volume.CapabilitiesResponse { logrus.Infof("Hit Capabilities() endpoint") return &volume.CapabilitiesResponse{ - volume.Capability{ - "local", + Capabilities: volume.Capability{ + Scope: "local", }, } } @@ -260,7 +260,7 @@ func (d *DirDriver) Path(req *volume.PathRequest) (*volume.PathResponse, error) } return &volume.PathResponse{ - vol.path, + Mountpoint: vol.path, }, nil } @@ -280,7 +280,7 @@ func (d *DirDriver) Mount(req *volume.MountRequest) (*volume.MountResponse, erro vol.mounts[req.ID] = true return &volume.MountResponse{ - vol.path, + Mountpoint: vol.path, }, nil } diff --git a/test/utils/common_function_test.go b/test/utils/common_function_test.go index 003d490ce..c996a302c 100644 --- a/test/utils/common_function_test.go +++ b/test/utils/common_function_test.go @@ -90,24 +90,24 @@ var _ = Describe("Common functions test", func() { Entry("Command exist", "Fakecmd", false), ) - It("Test WriteJsonFile", func() { - type testJson struct { + It("Test WriteJSONFile", func() { + type testJSON struct { Item1 int Item2 []string } - compareData := &testJson{} + compareData := &testJSON{} - testData := &testJson{ + testData := &testJSON{ Item1: 5, Item2: []string{"test"}, } testByte, _ := json.Marshal(testData) - err := WriteJsonFile(testByte, "/tmp/testJson") + err := WriteJSONFile(testByte, "/tmp/testJSON") Expect(err).To(BeNil(), "Failed to write JSON to file.") - read, err := os.Open("/tmp/testJson") + read, err := os.Open("/tmp/testJSON") defer read.Close() Expect(err).To(BeNil(), "Can not find the JSON file after we write it.") diff --git a/test/utils/matchers.go b/test/utils/matchers.go index 17ff3ea75..288779b63 100644 --- a/test/utils/matchers.go +++ b/test/utils/matchers.go @@ -1,11 +1,12 @@ package utils import ( + "encoding/json" "fmt" "net/url" "github.com/containers/common/pkg/config" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:golint,stylecheck "github.com/onsi/gomega/format" "github.com/onsi/gomega/gexec" "github.com/onsi/gomega/matchers" @@ -95,7 +96,7 @@ func (matcher *URLMatcher) Match(actual interface{}) (bool, error) { if !ok { return false, fmt.Errorf("VerifyURL requires string inputs %T is not supported", matcher.Expected) } - e_uri, err := url.Parse(e) + eURI, err := url.Parse(e) if err != nil { return false, err } @@ -104,12 +105,12 @@ func (matcher *URLMatcher) Match(actual interface{}) (bool, error) { if !ok { return false, fmt.Errorf("VerifyURL requires string inputs %T is not supported", actual) } - a_uri, err := url.Parse(a) + aURI, err := url.Parse(a) if err != nil { return false, err } - return (&matchers.EqualMatcher{Expected: e_uri}).Match(a_uri) + return (&matchers.EqualMatcher{Expected: eURI}).Match(aURI) } type ExitMatcher struct { @@ -166,3 +167,32 @@ func (matcher *ExitMatcher) MatchMayChangeInTheFuture(actual interface{}) bool { } return true } + +type ValidJSONMatcher struct { + types.GomegaMatcher +} + +func BeValidJSON() *ValidJSONMatcher { + return &ValidJSONMatcher{} +} + +func (matcher *ValidJSONMatcher) Match(actual interface{}) (success bool, err error) { + s, ok := actual.(string) + if !ok { + return false, fmt.Errorf("ValidJSONMatcher expects a string, not %q", actual) + } + + var i interface{} + if err := json.Unmarshal([]byte(s), &i); err != nil { + return false, nil + } + return true, nil +} + +func (matcher *ValidJSONMatcher) FailureMessage(actual interface{}) (message string) { + return format.Message(actual, "to be valid JSON") +} + +func (matcher *ValidJSONMatcher) NegatedFailureMessage(actual interface{}) (message string) { + return format.Message(actual, "to _not_ be valid JSON") +} diff --git a/test/utils/utils.go b/test/utils/utils.go index 4a57d9ce7..944c1ac3c 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -13,9 +13,9 @@ import ( "time" "github.com/containers/storage/pkg/parsers/kernel" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - . "github.com/onsi/gomega/gexec" + . "github.com/onsi/ginkgo" //nolint:golint,stylecheck + . "github.com/onsi/gomega" //nolint:golint,stylecheck + . "github.com/onsi/gomega/gexec" //nolint:golint,stylecheck ) var ( @@ -439,25 +439,21 @@ func IsKernelNewerThan(version string) (bool, error) { return true, nil } return false, nil - } // IsCommandAvailable check if command exist func IsCommandAvailable(command string) bool { check := exec.Command("bash", "-c", strings.Join([]string{"command -v", command}, " ")) err := check.Run() - if err != nil { - return false - } - return true + return err == nil } -// WriteJsonFile write json format data to a json file -func WriteJsonFile(data []byte, filePath string) error { +// WriteJSONFile write json format data to a json file +func WriteJSONFile(data []byte, filePath string) error { var jsonData map[string]interface{} json.Unmarshal(data, &jsonData) - formatJson, _ := json.MarshalIndent(jsonData, "", " ") - return ioutil.WriteFile(filePath, formatJson, 0644) + formatJSON, _ := json.MarshalIndent(jsonData, "", " ") + return ioutil.WriteFile(filePath, formatJSON, 0644) } // Containerized check the podman command run inside container @@ -471,10 +467,7 @@ func Containerized() bool { // shrug, if we cannot read that file, return false return false } - if strings.Index(string(b), "docker") > -1 { - return true - } - return false + return strings.Contains(string(b), "docker") } func init() { @@ -485,7 +478,6 @@ var randomLetters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ // RandomString returns a string of given length composed of random characters func RandomString(n int) string { - b := make([]rune, n) for i := range b { b[i] = randomLetters[rand.Intn(len(randomLetters))] |