github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/volume_create_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	. "github.com/containers/podman/v3/test/utils"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gexec"
    11  )
    12  
    13  var _ = Describe("Podman volume create", func() {
    14  	var (
    15  		tempdir    string
    16  		err        error
    17  		podmanTest *PodmanTestIntegration
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		tempdir, err = CreateTempDirInTempDir()
    22  		if err != nil {
    23  			os.Exit(1)
    24  		}
    25  		podmanTest = PodmanTestCreate(tempdir)
    26  		podmanTest.Setup()
    27  		podmanTest.SeedImages()
    28  	})
    29  
    30  	AfterEach(func() {
    31  		podmanTest.CleanupVolume()
    32  		f := CurrentGinkgoTestDescription()
    33  		processTestResult(f)
    34  
    35  	})
    36  
    37  	It("podman create volume", func() {
    38  		session := podmanTest.Podman([]string{"volume", "create"})
    39  		session.WaitWithDefaultTimeout()
    40  		volName := session.OutputToString()
    41  		Expect(session).Should(Exit(0))
    42  
    43  		check := podmanTest.Podman([]string{"volume", "ls", "-q"})
    44  		check.WaitWithDefaultTimeout()
    45  		match, _ := check.GrepString(volName)
    46  		Expect(match).To(BeTrue())
    47  		Expect(len(check.OutputToStringArray())).To(Equal(1))
    48  	})
    49  
    50  	It("podman create volume with name", func() {
    51  		session := podmanTest.Podman([]string{"volume", "create", "myvol"})
    52  		session.WaitWithDefaultTimeout()
    53  		volName := session.OutputToString()
    54  		Expect(session).Should(Exit(0))
    55  
    56  		check := podmanTest.Podman([]string{"volume", "ls", "-q"})
    57  		check.WaitWithDefaultTimeout()
    58  		match, _ := check.GrepString(volName)
    59  		Expect(match).To(BeTrue())
    60  		Expect(len(check.OutputToStringArray())).To(Equal(1))
    61  	})
    62  
    63  	It("podman create and export volume", func() {
    64  		if podmanTest.RemoteTest {
    65  			Skip("Volume export check does not work with a remote client")
    66  		}
    67  
    68  		session := podmanTest.Podman([]string{"volume", "create", "myvol"})
    69  		session.WaitWithDefaultTimeout()
    70  		volName := session.OutputToString()
    71  		Expect(session).Should(Exit(0))
    72  
    73  		session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"})
    74  		session.WaitWithDefaultTimeout()
    75  		Expect(session).Should(Exit(0))
    76  
    77  		check := podmanTest.Podman([]string{"volume", "export", volName})
    78  		check.WaitWithDefaultTimeout()
    79  		Expect(check.OutputToString()).To(ContainSubstring("hello"))
    80  	})
    81  
    82  	It("podman create and import volume", func() {
    83  		if podmanTest.RemoteTest {
    84  			Skip("Volume export check does not work with a remote client")
    85  		}
    86  
    87  		session := podmanTest.Podman([]string{"volume", "create", "my_vol"})
    88  		session.WaitWithDefaultTimeout()
    89  		volName := session.OutputToString()
    90  		Expect(session).Should(Exit(0))
    91  
    92  		session = podmanTest.Podman([]string{"run", "--volume", volName + ":/data", ALPINE, "sh", "-c", "echo hello >> " + "/data/test"})
    93  		session.WaitWithDefaultTimeout()
    94  		Expect(session).Should(Exit(0))
    95  
    96  		session = podmanTest.Podman([]string{"volume", "export", volName, "--output=hello.tar"})
    97  		session.WaitWithDefaultTimeout()
    98  		Expect(session).Should(Exit(0))
    99  
   100  		session = podmanTest.Podman([]string{"volume", "create", "my_vol2"})
   101  		session.WaitWithDefaultTimeout()
   102  		volName = session.OutputToString()
   103  		Expect(session).Should(Exit(0))
   104  
   105  		session = podmanTest.Podman([]string{"volume", "import", "my_vol2", "hello.tar"})
   106  		session.WaitWithDefaultTimeout()
   107  		volName = session.OutputToString()
   108  		Expect(session).Should(Exit(0))
   109  
   110  		session = podmanTest.Podman([]string{"run", "--volume", "my_vol2:/data", ALPINE, "cat", "/data/test"})
   111  		session.WaitWithDefaultTimeout()
   112  		Expect(session.OutputToString()).To(ContainSubstring("hello"))
   113  	})
   114  
   115  	It("podman import volume should fail", func() {
   116  		// try import on volume or source which does not exists
   117  		if podmanTest.RemoteTest {
   118  			Skip("Volume export check does not work with a remote client")
   119  		}
   120  
   121  		session := podmanTest.Podman([]string{"volume", "import", "notfound", "notfound.tar"})
   122  		session.WaitWithDefaultTimeout()
   123  		Expect(session).To(ExitWithError())
   124  	})
   125  
   126  	It("podman create volume with bad volume option", func() {
   127  		session := podmanTest.Podman([]string{"volume", "create", "--opt", "badOpt=bad"})
   128  		session.WaitWithDefaultTimeout()
   129  		Expect(session).To(ExitWithError())
   130  	})
   131  
   132  	It("podman create volume with o=uid,gid", func() {
   133  		volName := "testVol"
   134  		uid := "3000"
   135  		gid := "4000"
   136  		session := podmanTest.Podman([]string{"volume", "create", "--opt", fmt.Sprintf("o=uid=%s,gid=%s", uid, gid), volName})
   137  		session.WaitWithDefaultTimeout()
   138  		Expect(session).Should(Exit(0))
   139  
   140  		inspectUID := podmanTest.Podman([]string{"volume", "inspect", "--format", "{{ .UID }}", volName})
   141  		inspectUID.WaitWithDefaultTimeout()
   142  		Expect(inspectUID).Should(Exit(0))
   143  		Expect(inspectUID.OutputToString()).To(Equal(uid))
   144  
   145  		inspectGID := podmanTest.Podman([]string{"volume", "inspect", "--format", "{{ .GID }}", volName})
   146  		inspectGID.WaitWithDefaultTimeout()
   147  		Expect(inspectGID).Should(Exit(0))
   148  		Expect(inspectGID.OutputToString()).To(Equal(gid))
   149  
   150  		// options should containt `uid=3000,gid=4000:3000:4000`
   151  		optionFormat := `{{ .Options.o }}:{{ .Options.UID }}:{{ .Options.GID }}`
   152  		optionStrFormatExpect := fmt.Sprintf(`uid=%s,gid=%s:%s:%s`, uid, gid, uid, gid)
   153  		inspectOpts := podmanTest.Podman([]string{"volume", "inspect", "--format", optionFormat, volName})
   154  		inspectOpts.WaitWithDefaultTimeout()
   155  		Expect(inspectOpts).Should(Exit(0))
   156  		Expect(inspectOpts.OutputToString()).To(Equal(optionStrFormatExpect))
   157  	})
   158  })