github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/test/e2e/pod_top_test.go (about) 1 // +build !remoteclient 2 3 package integration 4 5 import ( 6 "fmt" 7 "os" 8 "time" 9 10 . "github.com/containers/libpod/test/utils" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Podman top", func() { 16 var ( 17 tempdir string 18 err error 19 podmanTest *PodmanTestIntegration 20 ) 21 22 BeforeEach(func() { 23 tempdir, err = CreateTempDirInTempDir() 24 if err != nil { 25 os.Exit(1) 26 } 27 podmanTest = PodmanTestCreate(tempdir) 28 podmanTest.Setup() 29 podmanTest.SeedImages() 30 }) 31 32 AfterEach(func() { 33 podmanTest.CleanupPod() 34 f := CurrentGinkgoTestDescription() 35 processTestResult(f) 36 37 }) 38 39 It("podman pod top without pod name or id", func() { 40 result := podmanTest.Podman([]string{"pod", "top"}) 41 result.WaitWithDefaultTimeout() 42 Expect(result.ExitCode()).To(Equal(125)) 43 }) 44 45 It("podman pod top on bogus pod", func() { 46 result := podmanTest.Podman([]string{"pod", "top", "1234"}) 47 result.WaitWithDefaultTimeout() 48 Expect(result.ExitCode()).To(Equal(125)) 49 }) 50 51 It("podman pod top on non-running pod", func() { 52 _, ec, podid := podmanTest.CreatePod("") 53 Expect(ec).To(Equal(0)) 54 55 result := podmanTest.Podman([]string{"top", podid}) 56 result.WaitWithDefaultTimeout() 57 Expect(result.ExitCode()).To(Equal(125)) 58 }) 59 60 It("podman pod top on pod", func() { 61 _, ec, podid := podmanTest.CreatePod("") 62 Expect(ec).To(Equal(0)) 63 64 session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 65 session.WaitWithDefaultTimeout() 66 Expect(session.ExitCode()).To(Equal(0)) 67 68 result := podmanTest.Podman([]string{"pod", "top", "-l"}) 69 result.WaitWithDefaultTimeout() 70 Expect(result.ExitCode()).To(Equal(0)) 71 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 72 }) 73 74 It("podman pod top with options", func() { 75 _, ec, podid := podmanTest.CreatePod("") 76 Expect(ec).To(Equal(0)) 77 78 session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 79 session.WaitWithDefaultTimeout() 80 Expect(session.ExitCode()).To(Equal(0)) 81 82 result := podmanTest.Podman([]string{"pod", "top", podid, "pid", "%C", "args"}) 83 result.WaitWithDefaultTimeout() 84 Expect(result.ExitCode()).To(Equal(0)) 85 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 86 }) 87 88 It("podman pod top on pod invalid options", func() { 89 _, ec, podid := podmanTest.CreatePod("") 90 Expect(ec).To(Equal(0)) 91 92 session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 93 session.WaitWithDefaultTimeout() 94 Expect(session.ExitCode()).To(Equal(0)) 95 96 // We need to pass -eo to force executing ps in the Alpine container. 97 // Alpines stripped down ps(1) is accepting any kind of weird input in 98 // contrast to others, such that a `ps invalid` will silently ignore 99 // the wrong input and still print the -ef output instead. 100 result := podmanTest.Podman([]string{"pod", "top", podid, "-eo", "invalid"}) 101 result.WaitWithDefaultTimeout() 102 Expect(result.ExitCode()).To(Equal(125)) 103 }) 104 105 It("podman pod top on pod with containers in same pid namespace", func() { 106 _, ec, podid := podmanTest.CreatePod("") 107 Expect(ec).To(Equal(0)) 108 109 session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 110 session.WaitWithDefaultTimeout() 111 Expect(session.ExitCode()).To(Equal(0)) 112 cid := session.OutputToString() 113 114 session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, "--pid", fmt.Sprintf("container:%s", cid), ALPINE, "top", "-d", "2"}) 115 session.WaitWithDefaultTimeout() 116 Expect(session.ExitCode()).To(Equal(0)) 117 118 result := podmanTest.Podman([]string{"pod", "top", podid}) 119 result.WaitWithDefaultTimeout() 120 Expect(result.ExitCode()).To(Equal(0)) 121 Expect(len(result.OutputToStringArray())).To(Equal(3)) 122 }) 123 124 It("podman pod top on pod with containers in different namespace", func() { 125 _, ec, podid := podmanTest.CreatePod("") 126 Expect(ec).To(Equal(0)) 127 128 session := podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 129 session.WaitWithDefaultTimeout() 130 Expect(session.ExitCode()).To(Equal(0)) 131 132 session = podmanTest.Podman([]string{"run", "-d", "--pod", podid, ALPINE, "top", "-d", "2"}) 133 session.WaitWithDefaultTimeout() 134 Expect(session.ExitCode()).To(Equal(0)) 135 136 for i := 0; i < 10; i++ { 137 fmt.Println("Waiting for containers to be running .... ") 138 if podmanTest.NumberOfContainersRunning() == 2 { 139 break 140 } 141 time.Sleep(1 * time.Second) 142 } 143 result := podmanTest.Podman([]string{"pod", "top", podid}) 144 result.WaitWithDefaultTimeout() 145 Expect(result.ExitCode()).To(Equal(0)) 146 Expect(len(result.OutputToStringArray())).To(Equal(3)) 147 }) 148 })