github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/rename_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 rename", 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.Cleanup()
    31  		f := CurrentGinkgoTestDescription()
    32  		processTestResult(f)
    33  
    34  	})
    35  
    36  	It("podman rename on non-existent container", func() {
    37  		session := podmanTest.Podman([]string{"rename", "doesNotExist", "aNewName"})
    38  		session.WaitWithDefaultTimeout()
    39  		Expect(session).To(ExitWithError())
    40  	})
    41  
    42  	It("Podman rename on existing container with bad name", func() {
    43  		ctrName := "testCtr"
    44  		ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
    45  		ctr.WaitWithDefaultTimeout()
    46  		Expect(ctr).Should(Exit(0))
    47  
    48  		newName := "invalid<>:char"
    49  		rename := podmanTest.Podman([]string{"rename", ctrName, newName})
    50  		rename.WaitWithDefaultTimeout()
    51  		Expect(rename).To(ExitWithError())
    52  
    53  		ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", ctrName), "--format", "{{ .Names }}"})
    54  		ps.WaitWithDefaultTimeout()
    55  		Expect(ps).Should(Exit(0))
    56  		Expect(ps.OutputToString()).To(ContainSubstring(ctrName))
    57  	})
    58  
    59  	It("Successfully rename a created container", func() {
    60  		ctrName := "testCtr"
    61  		ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
    62  		ctr.WaitWithDefaultTimeout()
    63  		Expect(ctr).Should(Exit(0))
    64  
    65  		newName := "aNewName"
    66  		rename := podmanTest.Podman([]string{"rename", ctrName, newName})
    67  		rename.WaitWithDefaultTimeout()
    68  		Expect(rename).Should(Exit(0))
    69  
    70  		ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"})
    71  		ps.WaitWithDefaultTimeout()
    72  		Expect(ps).Should(Exit(0))
    73  		Expect(ps.OutputToString()).To(ContainSubstring(newName))
    74  	})
    75  
    76  	It("Successfully rename a created container and test event generated", func() {
    77  		ctrName := "testCtr"
    78  		ctr := podmanTest.Podman([]string{"create", "--name", ctrName, ALPINE, "top"})
    79  		ctr.WaitWithDefaultTimeout()
    80  		Expect(ctr).Should(Exit(0))
    81  
    82  		newName := "aNewName"
    83  		rename := podmanTest.Podman([]string{"rename", ctrName, newName})
    84  		rename.WaitWithDefaultTimeout()
    85  		Expect(rename).Should(Exit(0))
    86  
    87  		result := podmanTest.Podman([]string{"events", "--stream=false", "--filter", "container=aNewName"})
    88  		result.WaitWithDefaultTimeout()
    89  		Expect(result).Should(Exit(0))
    90  		Expect(result.OutputToString()).To(ContainSubstring("rename"))
    91  	})
    92  
    93  	It("Successfully rename a running container", func() {
    94  		ctrName := "testCtr"
    95  		ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
    96  		ctr.WaitWithDefaultTimeout()
    97  		Expect(ctr).Should(Exit(0))
    98  
    99  		newName := "aNewName"
   100  		rename := podmanTest.Podman([]string{"rename", ctrName, newName})
   101  		rename.WaitWithDefaultTimeout()
   102  		Expect(rename).Should(Exit(0))
   103  
   104  		ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"})
   105  		ps.WaitWithDefaultTimeout()
   106  		Expect(ps).Should(Exit(0))
   107  		Expect(ps.OutputToString()).To(ContainSubstring(newName))
   108  	})
   109  
   110  	It("Rename a running container with exec sessions", func() {
   111  		ctrName := "testCtr"
   112  		ctr := podmanTest.Podman([]string{"run", "-d", "--name", ctrName, ALPINE, "top"})
   113  		ctr.WaitWithDefaultTimeout()
   114  		Expect(ctr).Should(Exit(0))
   115  
   116  		exec := podmanTest.Podman([]string{"exec", "-d", ctrName, "top"})
   117  		exec.WaitWithDefaultTimeout()
   118  		Expect(exec).Should(Exit(0))
   119  
   120  		newName := "aNewName"
   121  		rename := podmanTest.Podman([]string{"rename", ctrName, newName})
   122  		rename.WaitWithDefaultTimeout()
   123  		Expect(rename).Should(Exit(0))
   124  
   125  		ps := podmanTest.Podman([]string{"ps", "-aq", "--filter", fmt.Sprintf("name=%s", newName), "--format", "{{ .Names }}"})
   126  		ps.WaitWithDefaultTimeout()
   127  		Expect(ps).Should(Exit(0))
   128  		Expect(ps.OutputToString()).To(ContainSubstring(newName))
   129  	})
   130  
   131  	It("Rename a container that is part of a pod", func() {
   132  		podName := "testPod"
   133  		infraName := "infra1"
   134  		pod := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-name", infraName})
   135  		pod.WaitWithDefaultTimeout()
   136  		Expect(pod).Should(Exit(0))
   137  
   138  		infraName2 := "infra2"
   139  		rename := podmanTest.Podman([]string{"rename", infraName, infraName2})
   140  		rename.WaitWithDefaultTimeout()
   141  		Expect(rename).Should(Exit(0))
   142  
   143  		remove := podmanTest.Podman([]string{"pod", "rm", "-f", podName})
   144  		remove.WaitWithDefaultTimeout()
   145  		Expect(remove).Should(Exit(0))
   146  
   147  		create := podmanTest.Podman([]string{"create", "--name", infraName2, ALPINE, "top"})
   148  		create.WaitWithDefaultTimeout()
   149  		Expect(create).Should(Exit(0))
   150  
   151  		create2 := podmanTest.Podman([]string{"create", "--name", infraName, ALPINE, "top"})
   152  		create2.WaitWithDefaultTimeout()
   153  		Expect(create2).Should(Exit(0))
   154  	})
   155  })