github.com/AbhinandanKurakure/podman/v3@v3.4.10/test/e2e/rename_test.go (about)

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