6
. "github.com/containers/podman/v5/test/utils"
7
. "github.com/onsi/ginkgo/v2"
8
. "github.com/onsi/gomega"
11
var _ = Describe("podman rename", func() {
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())
19
It("Podman rename on existing container with bad name", func() {
21
ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
22
ctr.WaitWithDefaultTimeout()
23
Expect(ctr).Should(ExitCleanly())
25
newName := "invalid<>:char"
26
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
27
rename.WaitWithDefaultTimeout()
28
Expect(rename).To(ExitWithError())
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))
36
It("Successfully rename a created container", func() {
38
ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
39
ctr.WaitWithDefaultTimeout()
40
Expect(ctr).Should(ExitCleanly())
43
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
44
rename.WaitWithDefaultTimeout()
45
Expect(rename).Should(ExitCleanly())
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))
53
It("Successfully rename a created container and test event generated", func() {
55
ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
56
ctr.WaitWithDefaultTimeout()
57
Expect(ctr).Should(ExitCleanly())
60
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
61
rename.WaitWithDefaultTimeout()
62
Expect(rename).Should(ExitCleanly())
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"))
70
It("Successfully rename a running container", func() {
72
ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
73
ctr.WaitWithDefaultTimeout()
74
Expect(ctr).Should(ExitCleanly())
77
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
78
rename.WaitWithDefaultTimeout()
79
Expect(rename).Should(ExitCleanly())
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))
87
It("Rename a running container with exec sessions", func() {
89
ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
90
ctr.WaitWithDefaultTimeout()
91
Expect(ctr).Should(ExitCleanly())
93
exec := podmanTest.Podman([]string{"exec", "-d", ctrName, "top"})
94
exec.WaitWithDefaultTimeout()
95
Expect(exec).Should(ExitCleanly())
98
rename := podmanTest.Podman([]string{"rename", ctrName, newName})
99
rename.WaitWithDefaultTimeout()
100
Expect(rename).Should(ExitCleanly())
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))
108
It("Rename a container that is part of a pod", func() {
110
infraName := "infra1"
111
pod := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-name", infraName})
112
pod.WaitWithDefaultTimeout()
113
Expect(pod).Should(ExitCleanly())
115
infraName2 := "infra2"
116
rename := podmanTest.Podman([]string{"rename", infraName, infraName2})
117
rename.WaitWithDefaultTimeout()
118
Expect(rename).Should(ExitCleanly())
120
remove := podmanTest.Podman([]string{"pod", "rm", "-f", podName})
121
remove.WaitWithDefaultTimeout()
122
Expect(remove).Should(ExitCleanly())
124
create := podmanTest.Podman([]string{"create", "--name", infraName2, ALPINE, "top"})
125
create.WaitWithDefaultTimeout()
126
Expect(create).Should(ExitCleanly())
128
create2 := podmanTest.Podman([]string{"create", "--name", infraName, ALPINE, "top"})
129
create2.WaitWithDefaultTimeout()
130
Expect(create2).Should(ExitCleanly())