github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/volume_ls_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 7 . "github.com/hanks177/podman/v4/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 ls", 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 }) 28 29 AfterEach(func() { 30 podmanTest.CleanupVolume() 31 f := CurrentGinkgoTestDescription() 32 processTestResult(f) 33 34 }) 35 36 It("podman ls volume", func() { 37 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 38 session.WaitWithDefaultTimeout() 39 Expect(session).Should(Exit(0)) 40 41 session = podmanTest.Podman([]string{"volume", "ls"}) 42 session.WaitWithDefaultTimeout() 43 Expect(session).Should(Exit(0)) 44 Expect(session.OutputToStringArray()).To(HaveLen(2)) 45 }) 46 47 It("podman ls volume filter with a key pattern", func() { 48 session := podmanTest.Podman([]string{"volume", "create", "--label", "helloworld=world", "myvol2"}) 49 session.WaitWithDefaultTimeout() 50 Expect(session).Should(Exit(0)) 51 52 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=hello*"}) 53 session.WaitWithDefaultTimeout() 54 Expect(session).Should(Exit(0)) 55 Expect(session.OutputToStringArray()).To(HaveLen(2)) 56 }) 57 58 It("podman ls volume with JSON format", func() { 59 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 60 session.WaitWithDefaultTimeout() 61 Expect(session).Should(Exit(0)) 62 63 session = podmanTest.Podman([]string{"volume", "ls", "--format", "json"}) 64 session.WaitWithDefaultTimeout() 65 Expect(session).Should(Exit(0)) 66 Expect(session.OutputToString()).To(BeValidJSON()) 67 }) 68 69 It("podman ls volume with Go template", func() { 70 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 71 session.WaitWithDefaultTimeout() 72 Expect(session).Should(Exit(0)) 73 74 session = podmanTest.Podman([]string{"volume", "ls", "--format", "table {{.Name}} {{.Driver}} {{.Scope}}"}) 75 session.WaitWithDefaultTimeout() 76 77 Expect(session).Should(Exit(0)) 78 Expect(session.OutputToStringArray()).To(HaveLen(1), session.OutputToString()) 79 }) 80 81 It("podman ls volume with --filter flag", func() { 82 session := podmanTest.Podman([]string{"volume", "create", "--label", "foo=bar", "myvol"}) 83 volName := session.OutputToString() 84 session.WaitWithDefaultTimeout() 85 Expect(session).Should(Exit(0)) 86 87 session = podmanTest.Podman([]string{"volume", "create"}) 88 session.WaitWithDefaultTimeout() 89 Expect(session).Should(Exit(0)) 90 91 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo"}) 92 session.WaitWithDefaultTimeout() 93 Expect(session).Should(Exit(0)) 94 Expect(session.OutputToStringArray()).To(HaveLen(2)) 95 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 96 97 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=foo"}) 98 session.WaitWithDefaultTimeout() 99 Expect(session).Should(Exit(0)) 100 Expect(session.OutputToStringArray()).To(BeEmpty()) 101 102 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar"}) 103 session.WaitWithDefaultTimeout() 104 Expect(session).Should(Exit(0)) 105 Expect(session.OutputToStringArray()).To(HaveLen(2)) 106 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 107 108 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=baz"}) 109 session.WaitWithDefaultTimeout() 110 Expect(session).Should(Exit(0)) 111 Expect(session.OutputToStringArray()).To(BeEmpty()) 112 }) 113 114 It("podman ls volume with --filter until flag", func() { 115 session := podmanTest.Podman([]string{"volume", "create"}) 116 session.WaitWithDefaultTimeout() 117 Expect(session).Should(Exit(0)) 118 119 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "until=5000000000"}) 120 session.WaitWithDefaultTimeout() 121 Expect(session).Should(Exit(0)) 122 Expect(session.OutputToStringArray()).To(HaveLen(2)) 123 124 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "until=50000"}) 125 session.WaitWithDefaultTimeout() 126 Expect(session).Should(Exit(0)) 127 Expect(session.OutputToStringArray()).To(BeEmpty()) 128 }) 129 130 It("podman volume ls with --filter dangling", func() { 131 volName1 := "volume1" 132 session := podmanTest.Podman([]string{"volume", "create", volName1}) 133 session.WaitWithDefaultTimeout() 134 Expect(session).Should(Exit(0)) 135 136 volName2 := "volume2" 137 session2 := podmanTest.Podman([]string{"volume", "create", volName2}) 138 session2.WaitWithDefaultTimeout() 139 Expect(session2).Should(Exit(0)) 140 141 ctr := podmanTest.Podman([]string{"create", "-v", fmt.Sprintf("%s:/test", volName2), ALPINE, "sh"}) 142 ctr.WaitWithDefaultTimeout() 143 Expect(ctr).Should(Exit(0)) 144 145 lsNoDangling := podmanTest.Podman([]string{"volume", "ls", "--filter", "dangling=false", "--quiet"}) 146 lsNoDangling.WaitWithDefaultTimeout() 147 Expect(lsNoDangling).Should(Exit(0)) 148 Expect(lsNoDangling.OutputToString()).To(ContainSubstring(volName2)) 149 150 lsDangling := podmanTest.Podman([]string{"volume", "ls", "--filter", "dangling=true", "--quiet"}) 151 lsDangling.WaitWithDefaultTimeout() 152 Expect(lsDangling).Should(Exit(0)) 153 Expect(lsDangling.OutputToString()).To(ContainSubstring(volName1)) 154 }) 155 It("podman ls volume with multiple --filter flag", func() { 156 session := podmanTest.Podman([]string{"volume", "create", "--label", "foo=bar", "myvol"}) 157 volName := session.OutputToString() 158 session.WaitWithDefaultTimeout() 159 Expect(session).Should(Exit(0)) 160 161 session = podmanTest.Podman([]string{"volume", "create", "--label", "foo2=bar2", "anothervol"}) 162 anotherVol := session.OutputToString() 163 session.WaitWithDefaultTimeout() 164 Expect(session).Should(Exit(0)) 165 166 session = podmanTest.Podman([]string{"volume", "create"}) 167 session.WaitWithDefaultTimeout() 168 Expect(session).Should(Exit(0)) 169 170 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo", "--filter", "label=foo2"}) 171 session.WaitWithDefaultTimeout() 172 Expect(session).Should(Exit(0)) 173 Expect(session.OutputToStringArray()).To(HaveLen(3)) 174 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 175 Expect(session.OutputToStringArray()[2]).To(ContainSubstring(anotherVol)) 176 177 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar", "--filter", "label=foo2=bar2"}) 178 session.WaitWithDefaultTimeout() 179 Expect(session).Should(Exit(0)) 180 Expect(session.OutputToStringArray()).To(HaveLen(3)) 181 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 182 Expect(session.OutputToStringArray()[2]).To(ContainSubstring(anotherVol)) 183 }) 184 })