github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/top_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 6 . "github.com/hanks177/podman/v4/test/utils" 7 . "github.com/onsi/ginkgo" 8 . "github.com/onsi/gomega" 9 . "github.com/onsi/gomega/gexec" 10 ) 11 12 var _ = Describe("Podman top", func() { 13 var ( 14 tempdir string 15 err error 16 podmanTest *PodmanTestIntegration 17 ) 18 19 BeforeEach(func() { 20 tempdir, err = CreateTempDirInTempDir() 21 if err != nil { 22 os.Exit(1) 23 } 24 podmanTest = PodmanTestCreate(tempdir) 25 podmanTest.Setup() 26 }) 27 28 AfterEach(func() { 29 podmanTest.Cleanup() 30 f := CurrentGinkgoTestDescription() 31 processTestResult(f) 32 33 }) 34 35 It("podman top without container name or id", func() { 36 result := podmanTest.Podman([]string{"top"}) 37 result.WaitWithDefaultTimeout() 38 Expect(result).Should(Exit(125)) 39 }) 40 41 It("podman top on bogus container", func() { 42 result := podmanTest.Podman([]string{"top", "1234"}) 43 result.WaitWithDefaultTimeout() 44 Expect(result).Should(Exit(125)) 45 }) 46 47 It("podman top on non-running container", func() { 48 _, ec, cid := podmanTest.RunLsContainer("") 49 Expect(ec).To(Equal(0)) 50 result := podmanTest.Podman([]string{"top", cid}) 51 result.WaitWithDefaultTimeout() 52 Expect(result).Should(Exit(125)) 53 }) 54 55 It("podman top on container", func() { 56 session := podmanTest.Podman([]string{"run", "--name", "test", "-d", ALPINE, "top", "-d", "2"}) 57 session.WaitWithDefaultTimeout() 58 Expect(session).Should(Exit(0)) 59 60 result := podmanTest.Podman([]string{"top", "test"}) 61 result.WaitWithDefaultTimeout() 62 Expect(result).Should(Exit(0)) 63 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 64 }) 65 66 It("podman container top on container", func() { 67 session := podmanTest.Podman([]string{"container", "run", "--name", "test", "-d", ALPINE, "top", "-d", "2"}) 68 session.WaitWithDefaultTimeout() 69 Expect(session).Should(Exit(0)) 70 71 result := podmanTest.Podman([]string{"container", "top", "test"}) 72 result.WaitWithDefaultTimeout() 73 Expect(result).Should(Exit(0)) 74 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 75 76 // Just a smoke test since groups may change over time. 77 result = podmanTest.Podman([]string{"container", "top", "test", "groups", "hgroups"}) 78 result.WaitWithDefaultTimeout() 79 Expect(result).Should(Exit(0)) 80 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 81 }) 82 83 It("podman top with options", func() { 84 session := podmanTest.Podman([]string{"run", "-d", ALPINE, "top", "-d", "2"}) 85 session.WaitWithDefaultTimeout() 86 Expect(session).Should(Exit(0)) 87 88 result := podmanTest.Podman([]string{"top", session.OutputToString(), "pid", "%C", "args"}) 89 result.WaitWithDefaultTimeout() 90 Expect(result).Should(Exit(0)) 91 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 92 }) 93 94 It("podman top with ps(1) options", func() { 95 session := podmanTest.Podman([]string{"run", "-d", ALPINE, "top", "-d", "2"}) 96 session.WaitWithDefaultTimeout() 97 Expect(session).Should(Exit(0)) 98 99 result := podmanTest.Podman([]string{"top", session.OutputToString(), "aux"}) 100 result.WaitWithDefaultTimeout() 101 Expect(result).Should(Exit(0)) 102 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 103 104 result = podmanTest.Podman([]string{"top", session.OutputToString(), "ax -o args"}) 105 result.WaitWithDefaultTimeout() 106 Expect(result).Should(Exit(0)) 107 Expect(result.OutputToStringArray()).To(Equal([]string{"COMMAND", "top -d 2"})) 108 }) 109 110 It("podman top with comma-separated options", func() { 111 session := podmanTest.Podman([]string{"run", "-d", ALPINE, "top", "-d", "2"}) 112 session.WaitWithDefaultTimeout() 113 Expect(session).Should(Exit(0)) 114 115 result := podmanTest.Podman([]string{"top", session.OutputToString(), "user,pid,comm"}) 116 result.WaitWithDefaultTimeout() 117 Expect(result).Should(Exit(0)) 118 Expect(len(result.OutputToStringArray())).To(BeNumerically(">", 1)) 119 }) 120 121 It("podman top on container invalid options", func() { 122 top := podmanTest.RunTopContainer("") 123 top.WaitWithDefaultTimeout() 124 Expect(top).Should(Exit(0)) 125 cid := top.OutputToString() 126 127 // We need to pass -eo to force executing ps in the Alpine container. 128 // Alpines stripped down ps(1) is accepting any kind of weird input in 129 // contrast to others, such that a `ps invalid` will silently ignore 130 // the wrong input and still print the -ef output instead. 131 result := podmanTest.Podman([]string{"top", cid, "-eo", "invalid"}) 132 result.WaitWithDefaultTimeout() 133 Expect(result).Should(Exit(125)) 134 }) 135 136 })