github.com/containers/podman/v4@v4.9.4/test/e2e/volume_ls_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 6 . "github.com/containers/podman/v4/test/utils" 7 . "github.com/onsi/ginkgo/v2" 8 . "github.com/onsi/gomega" 9 ) 10 11 var _ = Describe("Podman volume ls", func() { 12 13 AfterEach(func() { 14 podmanTest.CleanupVolume() 15 }) 16 17 It("podman ls volume", func() { 18 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 19 session.WaitWithDefaultTimeout() 20 Expect(session).Should(ExitCleanly()) 21 22 session = podmanTest.Podman([]string{"volume", "ls"}) 23 session.WaitWithDefaultTimeout() 24 Expect(session).Should(ExitCleanly()) 25 Expect(session.OutputToStringArray()).To(HaveLen(2)) 26 }) 27 28 It("podman ls volume filter with comma label", func() { 29 session := podmanTest.Podman([]string{"volume", "create", "--label", "test=with,comma", "myvol3"}) 30 session.WaitWithDefaultTimeout() 31 Expect(session).Should(ExitCleanly()) 32 33 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=test=with,comma"}) 34 session.WaitWithDefaultTimeout() 35 Expect(session).Should(ExitCleanly()) 36 Expect(session.OutputToStringArray()).To(HaveLen(2)) 37 }) 38 39 It("podman ls volume filter with a key pattern", func() { 40 session := podmanTest.Podman([]string{"volume", "create", "--label", "helloworld=world", "myvol2"}) 41 session.WaitWithDefaultTimeout() 42 Expect(session).Should(ExitCleanly()) 43 44 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=hello*"}) 45 session.WaitWithDefaultTimeout() 46 Expect(session).Should(ExitCleanly()) 47 Expect(session.OutputToStringArray()).To(HaveLen(2)) 48 }) 49 50 It("podman ls volume with JSON format", func() { 51 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 52 session.WaitWithDefaultTimeout() 53 Expect(session).Should(ExitCleanly()) 54 55 session = podmanTest.Podman([]string{"volume", "ls", "--format", "json"}) 56 session.WaitWithDefaultTimeout() 57 Expect(session).Should(ExitCleanly()) 58 Expect(session.OutputToString()).To(BeValidJSON()) 59 }) 60 61 It("podman ls volume with Go template", func() { 62 session := podmanTest.Podman([]string{"volume", "create", "myvol"}) 63 session.WaitWithDefaultTimeout() 64 Expect(session).Should(ExitCleanly()) 65 66 session = podmanTest.Podman([]string{"volume", "ls", "--format", "table {{.Name}} {{.Driver}} {{.Scope}}"}) 67 session.WaitWithDefaultTimeout() 68 69 Expect(session).Should(ExitCleanly()) 70 arr := session.OutputToStringArray() 71 Expect(arr).To(HaveLen(2)) 72 Expect(arr[0]).To(ContainSubstring("NAME")) 73 Expect(arr[1]).To(ContainSubstring("myvol")) 74 }) 75 76 It("podman ls volume with --filter flag", func() { 77 session := podmanTest.Podman([]string{"volume", "create", "--label", "foo=bar", "myvol"}) 78 volName := session.OutputToString() 79 session.WaitWithDefaultTimeout() 80 Expect(session).Should(ExitCleanly()) 81 82 session = podmanTest.Podman([]string{"volume", "create"}) 83 session.WaitWithDefaultTimeout() 84 Expect(session).Should(ExitCleanly()) 85 86 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo"}) 87 session.WaitWithDefaultTimeout() 88 Expect(session).Should(ExitCleanly()) 89 Expect(session.OutputToStringArray()).To(HaveLen(2)) 90 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 91 92 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=foo"}) 93 session.WaitWithDefaultTimeout() 94 Expect(session).Should(ExitCleanly()) 95 Expect(session.OutputToStringArray()).To(BeEmpty()) 96 97 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar"}) 98 session.WaitWithDefaultTimeout() 99 Expect(session).Should(ExitCleanly()) 100 Expect(session.OutputToStringArray()).To(HaveLen(2)) 101 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName)) 102 103 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=baz"}) 104 session.WaitWithDefaultTimeout() 105 Expect(session).Should(ExitCleanly()) 106 Expect(session.OutputToStringArray()).To(BeEmpty()) 107 }) 108 109 It("podman ls volume with --filter until flag", func() { 110 session := podmanTest.Podman([]string{"volume", "create"}) 111 session.WaitWithDefaultTimeout() 112 Expect(session).Should(ExitCleanly()) 113 114 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "until=5000000000"}) 115 session.WaitWithDefaultTimeout() 116 Expect(session).Should(ExitCleanly()) 117 Expect(session.OutputToStringArray()).To(HaveLen(2)) 118 119 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "until=50000"}) 120 session.WaitWithDefaultTimeout() 121 Expect(session).Should(ExitCleanly()) 122 Expect(session.OutputToStringArray()).To(BeEmpty()) 123 }) 124 125 It("podman volume ls with --filter dangling", func() { 126 volName1 := "volume1" 127 session := podmanTest.Podman([]string{"volume", "create", volName1}) 128 session.WaitWithDefaultTimeout() 129 Expect(session).Should(ExitCleanly()) 130 131 volName2 := "volume2" 132 session2 := podmanTest.Podman([]string{"volume", "create", volName2}) 133 session2.WaitWithDefaultTimeout() 134 Expect(session2).Should(ExitCleanly()) 135 136 ctr := podmanTest.Podman([]string{"create", "-v", fmt.Sprintf("%s:/test", volName2), ALPINE, "sh"}) 137 ctr.WaitWithDefaultTimeout() 138 Expect(ctr).Should(ExitCleanly()) 139 140 lsNoDangling := podmanTest.Podman([]string{"volume", "ls", "--filter", "dangling=false", "--quiet"}) 141 lsNoDangling.WaitWithDefaultTimeout() 142 Expect(lsNoDangling).Should(ExitCleanly()) 143 Expect(lsNoDangling.OutputToString()).To(ContainSubstring(volName2)) 144 145 lsDangling := podmanTest.Podman([]string{"volume", "ls", "--filter", "dangling=true", "--quiet"}) 146 lsDangling.WaitWithDefaultTimeout() 147 Expect(lsDangling).Should(ExitCleanly()) 148 Expect(lsDangling.OutputToString()).To(ContainSubstring(volName1)) 149 }) 150 151 It("podman ls volume with --filter name", func() { 152 volName1 := "volume1" 153 session := podmanTest.Podman([]string{"volume", "create", volName1}) 154 session.WaitWithDefaultTimeout() 155 Expect(session).Should(ExitCleanly()) 156 157 volName2 := "volume2" 158 session2 := podmanTest.Podman([]string{"volume", "create", volName2}) 159 session2.WaitWithDefaultTimeout() 160 Expect(session2).Should(ExitCleanly()) 161 162 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "name=volume1*"}) 163 session.WaitWithDefaultTimeout() 164 Expect(session).Should(ExitCleanly()) 165 Expect(session.OutputToStringArray()).To(HaveLen(3)) 166 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName1)) 167 Expect(session.OutputToStringArray()[2]).To(ContainSubstring(volName2)) 168 169 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "name=volumex"}) 170 session.WaitWithDefaultTimeout() 171 Expect(session).Should(ExitCleanly()) 172 Expect(session.OutputToStringArray()).To(BeEmpty()) 173 174 session = podmanTest.Podman([]string{"volume", "ls", "--filter", "name=volume1"}) 175 session.WaitWithDefaultTimeout() 176 Expect(session).Should(ExitCleanly()) 177 Expect(session.OutputToStringArray()).To(HaveLen(2)) 178 Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName1)) 179 }) 180 181 It("podman ls volume with multiple --filter flag", func() { 182 session := podmanTest.Podman([]string{"volume", "create", "--label", "a=b", "--label", "b=c", "vol1"}) 183 session.WaitWithDefaultTimeout() 184 Expect(session).Should(ExitCleanly()) 185 186 vol1Name := session.OutputToString() 187 188 session = podmanTest.Podman([]string{"volume", "create", "--label", "b=c", "--label", "a=b", "vol2"}) 189 session.WaitWithDefaultTimeout() 190 Expect(session).Should(ExitCleanly()) 191 192 vol2Name := session.OutputToString() 193 194 session = podmanTest.Podman([]string{"volume", "create", "--label", "b=c", "--label", "c=d", "vol3"}) 195 session.WaitWithDefaultTimeout() 196 Expect(session).Should(ExitCleanly()) 197 198 vol3Name := session.OutputToString() 199 200 session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "label=a=b", "--filter", "label=b=c"}) 201 session.WaitWithDefaultTimeout() 202 Expect(session).Should(ExitCleanly()) 203 Expect(session.OutputToStringArray()).To(HaveLen(2)) 204 Expect(session.OutputToStringArray()[0]).To(Equal(vol1Name)) 205 Expect(session.OutputToStringArray()[1]).To(Equal(vol2Name)) 206 207 session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "label=c=d", "--filter", "label=b=c"}) 208 session.WaitWithDefaultTimeout() 209 Expect(session).Should(ExitCleanly()) 210 Expect(session.OutputToStringArray()).To(HaveLen(1)) 211 Expect(session.OutputToStringArray()[0]).To(Equal(vol3Name)) 212 }) 213 214 It("podman ls volume with --filter since/after", func() { 215 vol1 := "vol1" 216 vol2 := "vol2" 217 vol3 := "vol3" 218 219 session := podmanTest.Podman([]string{"volume", "create", vol1}) 220 session.WaitWithDefaultTimeout() 221 Expect(session).To(ExitCleanly()) 222 223 session = podmanTest.Podman([]string{"volume", "create", vol2}) 224 session.WaitWithDefaultTimeout() 225 Expect(session).To(ExitCleanly()) 226 227 session = podmanTest.Podman([]string{"volume", "create", vol3}) 228 session.WaitWithDefaultTimeout() 229 Expect(session).To(ExitCleanly()) 230 231 session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "since=" + vol1}) 232 session.WaitWithDefaultTimeout() 233 Expect(session.OutputToStringArray()).To(HaveLen(2)) 234 Expect(session.OutputToStringArray()[0]).To(Equal(vol2)) 235 Expect(session.OutputToStringArray()[1]).To(Equal(vol3)) 236 237 session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "after=" + vol1}) 238 session.WaitWithDefaultTimeout() 239 Expect(session.OutputToStringArray()).To(HaveLen(2)) 240 Expect(session.OutputToStringArray()[0]).To(Equal(vol2)) 241 Expect(session.OutputToStringArray()[1]).To(Equal(vol3)) 242 }) 243 })