github.com/containers/podman/v4@v4.9.4/test/e2e/rename_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 rename", func() { 12 13 It("podman rename on non-existent container", func() { 14 session := podmanTest.Podman([]string{"rename", "doesNotExist", "aNewName"}) 15 session.WaitWithDefaultTimeout() 16 Expect(session).To(ExitWithError()) 17 }) 18 19 It("Podman rename on existing container with bad name", func() { 20 ctrName := "testCtr" 21 ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"}) 22 ctr.WaitWithDefaultTimeout() 23 Expect(ctr).Should(ExitCleanly()) 24 25 newName := "invalid<>:char" 26 rename := podmanTest.Podman([]string{"rename", ctrName, newName}) 27 rename.WaitWithDefaultTimeout() 28 Expect(rename).To(ExitWithError()) 29 30 ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", ctrName), "--format", "{{ .Names }}"}) 31 ps.WaitWithDefaultTimeout() 32 Expect(ps).Should(ExitCleanly()) 33 Expect(ps.OutputToString()).To(ContainSubstring(ctrName)) 34 }) 35 36 It("Successfully rename a created container", func() { 37 ctrName := "testCtr" 38 ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"}) 39 ctr.WaitWithDefaultTimeout() 40 Expect(ctr).Should(ExitCleanly()) 41 42 newName := "aNewName" 43 rename := podmanTest.Podman([]string{"rename", ctrName, newName}) 44 rename.WaitWithDefaultTimeout() 45 Expect(rename).Should(ExitCleanly()) 46 47 ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"}) 48 ps.WaitWithDefaultTimeout() 49 Expect(ps).Should(ExitCleanly()) 50 Expect(ps.OutputToString()).To(ContainSubstring(newName)) 51 }) 52 53 It("Successfully rename a created container and test event generated", func() { 54 ctrName := "testCtr" 55 ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"}) 56 ctr.WaitWithDefaultTimeout() 57 Expect(ctr).Should(ExitCleanly()) 58 59 newName := "aNewName" 60 rename := podmanTest.Podman([]string{"rename", ctrName, newName}) 61 rename.WaitWithDefaultTimeout() 62 Expect(rename).Should(ExitCleanly()) 63 64 result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "container=aNewName"}) 65 result.WaitWithDefaultTimeout() 66 Expect(result).Should(ExitCleanly()) 67 Expect(result.OutputToString()).To(ContainSubstring("rename")) 68 }) 69 70 It("Successfully rename a running container", func() { 71 ctrName := "testCtr" 72 ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"}) 73 ctr.WaitWithDefaultTimeout() 74 Expect(ctr).Should(ExitCleanly()) 75 76 newName := "aNewName" 77 rename := podmanTest.Podman([]string{"rename", ctrName, newName}) 78 rename.WaitWithDefaultTimeout() 79 Expect(rename).Should(ExitCleanly()) 80 81 ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"}) 82 ps.WaitWithDefaultTimeout() 83 Expect(ps).Should(ExitCleanly()) 84 Expect(ps.OutputToString()).To(ContainSubstring(newName)) 85 }) 86 87 It("Rename a running container with exec sessions", func() { 88 ctrName := "testCtr" 89 ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"}) 90 ctr.WaitWithDefaultTimeout() 91 Expect(ctr).Should(ExitCleanly()) 92 93 exec := podmanTest.Podman([]string{"exec", "-d", ctrName, "top"}) 94 exec.WaitWithDefaultTimeout() 95 Expect(exec).Should(ExitCleanly()) 96 97 newName := "aNewName" 98 rename := podmanTest.Podman([]string{"rename", ctrName, newName}) 99 rename.WaitWithDefaultTimeout() 100 Expect(rename).Should(ExitCleanly()) 101 102 ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"}) 103 ps.WaitWithDefaultTimeout() 104 Expect(ps).Should(ExitCleanly()) 105 Expect(ps.OutputToString()).To(ContainSubstring(newName)) 106 }) 107 108 It("Rename a container that is part of a pod", func() { 109 podName := "testPod" 110 infraName := "infra1" 111 pod := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-name", infraName}) 112 pod.WaitWithDefaultTimeout() 113 Expect(pod).Should(ExitCleanly()) 114 115 infraName2 := "infra2" 116 rename := podmanTest.Podman([]string{"rename", infraName, infraName2}) 117 rename.WaitWithDefaultTimeout() 118 Expect(rename).Should(ExitCleanly()) 119 120 remove := podmanTest.Podman([]string{"pod", "rm", "-f", podName}) 121 remove.WaitWithDefaultTimeout() 122 Expect(remove).Should(ExitCleanly()) 123 124 create := podmanTest.Podman([]string{"create", "--name", infraName2, ALPINE, "top"}) 125 create.WaitWithDefaultTimeout() 126 Expect(create).Should(ExitCleanly()) 127 128 create2 := podmanTest.Podman([]string{"create", "--name", infraName, ALPINE, "top"}) 129 create2.WaitWithDefaultTimeout() 130 Expect(create2).Should(ExitCleanly()) 131 }) 132 })