diff --git a/test/e2e/volume_create_test.go b/test/e2e/volume_create_test.go index db3ed3b169..50b56c2b91 100644 --- a/test/e2e/volume_create_test.go +++ b/test/e2e/volume_create_test.go @@ -85,18 +85,30 @@ var _ = Describe("Podman volume create", func() { Skip("Volume export check does not work with a remote client") } - session := podmanTest.Podman([]string{"volume", "create", "myvol"}) + volName := "my_vol_" + RandomString(10) + session := podmanTest.Podman([]string{"volume", "create", volName}) session.WaitWithDefaultTimeout() - volName := session.OutputToString() Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(Equal(volName)) - session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"}) + helloString := "hello-" + RandomString(20) + session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo " + helloString + " >> /data/test"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) - check := podmanTest.Podman([]string{"volume", "export", volName}) + // export to tar file... + helloTar := filepath.Join(podmanTest.TempDir, "hello.tar") + check := podmanTest.Podman([]string{"volume", "export", "-o", helloTar, volName}) check.WaitWithDefaultTimeout() - Expect(check.OutputToString()).To(ContainSubstring("hello")) + Expect(check).Should(Exit(0)) + + // ...then confirm that tar file has our desired content. + // These flags emit filename to stderr (-v), contents to stdout + tar := SystemExec("tar", []string{"-x", "-v", "--to-stdout", "-f", helloTar}) + tar.WaitWithDefaultTimeout() + Expect(tar).To(Exit(0)) + Expect(tar.ErrorToString()).To(Equal("test")) + Expect(tar.OutputToString()).To(Equal(helloString)) }) It("podman create and import volume", func() { @@ -104,12 +116,13 @@ var _ = Describe("Podman volume create", func() { Skip("Volume export check does not work with a remote client") } - session := podmanTest.Podman([]string{"volume", "create", "my_vol"}) + volName := "my_vol_" + RandomString(10) + session := podmanTest.Podman([]string{"volume", "create", volName}) session.WaitWithDefaultTimeout() - volName := session.OutputToString() Expect(session).Should(Exit(0)) + Expect(session.OutputToString()).To(Equal(volName)) - session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"}) + session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> /data/test"}) session.WaitWithDefaultTimeout() Expect(session).Should(Exit(0)) diff --git a/test/system/160-volumes.bats b/test/system/160-volumes.bats index 7a6a4871da..369e95447b 100644 --- a/test/system/160-volumes.bats +++ b/test/system/160-volumes.bats @@ -258,6 +258,34 @@ EOF run_podman volume rm my_vol2 } +# stdout with NULs is easier to test here than in ginkgo +@test "podman volume export to stdout" { + skip_if_remote "N/A on podman-remote" + + local volname="myvol_$(random_string 10)" + local mountpoint="/data$(random_string 8)" + + run_podman volume create $volname + assert "$output" == "$volname" "volume create emits the name it was given" + + local content="mycontent-$(random_string 20)-the-end" + run_podman run --rm --volume "$volname:$mountpoint" $IMAGE \ + sh -c "echo $content >$mountpoint/testfile" + assert "$output" = "" + + # We can't use run_podman because bash can't handle NUL characters. + # Can't even store them in variables, so we need immediate redirection + # The "-v" is only for debugging: tar will emit the filename to stderr. + # If this test ever fails, that may give a clue. + echo "$_LOG_PROMPT $PODMAN volume export $volname | tar -x ..." + tar_output="$($PODMAN volume export $volname | tar -x -v --to-stdout)" + echo "$tar_output" + assert "$tar_output" == "$content" "extracted content" + + # Clean up + run_podman volume rm $volname +} + # Podman volume user test @test "podman volume user test" { is_rootless || skip "only meaningful when run rootless"