github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/test/e2e/port_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "os" 6 "strings" 7 8 . "github.com/hanks177/podman/v4/test/utils" 9 . "github.com/onsi/ginkgo" 10 . "github.com/onsi/gomega" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Podman port", func() { 15 var ( 16 tempdir string 17 err error 18 podmanTest *PodmanTestIntegration 19 ) 20 21 BeforeEach(func() { 22 tempdir, err = CreateTempDirInTempDir() 23 if err != nil { 24 os.Exit(1) 25 } 26 podmanTest = PodmanTestCreate(tempdir) 27 podmanTest.Setup() 28 }) 29 30 AfterEach(func() { 31 podmanTest.Cleanup() 32 f := CurrentGinkgoTestDescription() 33 processTestResult(f) 34 35 }) 36 37 It("podman port all and latest", func() { 38 result := podmanTest.Podman([]string{"port", "-a", "-l"}) 39 result.WaitWithDefaultTimeout() 40 Expect(result).To(ExitWithError()) 41 }) 42 43 It("podman port all and extra", func() { 44 result := podmanTest.Podman([]string{"port", "-a", "foobar"}) 45 result.WaitWithDefaultTimeout() 46 Expect(result).To(ExitWithError()) 47 }) 48 49 It("podman port -l nginx", func() { 50 session, cid := podmanTest.RunNginxWithHealthCheck("test1") 51 Expect(session).Should(Exit(0)) 52 53 if err := podmanTest.RunHealthCheck(cid); err != nil { 54 Fail(err.Error()) 55 } 56 57 if !IsRemote() { 58 cid = "-l" 59 } 60 result := podmanTest.Podman([]string{"port", cid}) 61 result.WaitWithDefaultTimeout() 62 Expect(result).Should(Exit(0)) 63 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 64 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) 65 }) 66 67 It("podman container port -l nginx", func() { 68 session, cid := podmanTest.RunNginxWithHealthCheck("") 69 Expect(session).Should(Exit(0)) 70 71 if err := podmanTest.RunHealthCheck(cid); err != nil { 72 Fail(err.Error()) 73 } 74 75 if !IsRemote() { 76 cid = "-l" 77 } 78 result := podmanTest.Podman([]string{"container", "port", cid}) 79 result.WaitWithDefaultTimeout() 80 Expect(result).Should(Exit(0)) 81 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 82 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) 83 }) 84 85 It("podman port -l port nginx", func() { 86 session, cid := podmanTest.RunNginxWithHealthCheck("") 87 Expect(session).Should(Exit(0)) 88 89 if err := podmanTest.RunHealthCheck(cid); err != nil { 90 Fail(err.Error()) 91 } 92 93 if !IsRemote() { 94 cid = "-l" 95 } 96 result := podmanTest.Podman([]string{"port", cid, "80"}) 97 result.WaitWithDefaultTimeout() 98 Expect(result).Should(Exit(0)) 99 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 100 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("0.0.0.0:%s", port)))) 101 }) 102 103 It("podman port -a nginx", func() { 104 session, cid := podmanTest.RunNginxWithHealthCheck("") 105 Expect(session).Should(Exit(0)) 106 107 if err := podmanTest.RunHealthCheck(cid); err != nil { 108 Fail(err.Error()) 109 } 110 111 result := podmanTest.Podman([]string{"port", "-a"}) 112 result.WaitWithDefaultTimeout() 113 Expect(result).Should(Exit(0)) 114 }) 115 116 It("podman port nginx by name", func() { 117 session, cid := podmanTest.RunNginxWithHealthCheck("portcheck") 118 Expect(session).Should(Exit(0)) 119 120 if err := podmanTest.RunHealthCheck(cid); err != nil { 121 Fail(err.Error()) 122 } 123 124 result := podmanTest.Podman([]string{"port", "portcheck"}) 125 result.WaitWithDefaultTimeout() 126 Expect(result).Should(Exit(0)) 127 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix("80/tcp -> 0.0.0.0:"))) 128 }) 129 130 It("podman port multiple ports", func() { 131 // Acquire and release locks 132 lock1 := GetPortLock("5000") 133 defer lock1.Unlock() 134 lock2 := GetPortLock("5001") 135 defer lock2.Unlock() 136 137 setup := podmanTest.Podman([]string{"run", "--name", "test", "-dt", "-p", "5000:5000", "-p", "5001:5001", ALPINE, "top"}) 138 setup.WaitWithDefaultTimeout() 139 Expect(setup).Should(Exit(0)) 140 141 // Check that the first port was honored 142 result1 := podmanTest.Podman([]string{"port", "test", "5000"}) 143 result1.WaitWithDefaultTimeout() 144 Expect(result1).Should(Exit(0)) 145 Expect(result1.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5000"))) 146 147 // Check that the second port was honored 148 result2 := podmanTest.Podman([]string{"port", "test", "5001"}) 149 result2.WaitWithDefaultTimeout() 150 Expect(result2).Should(Exit(0)) 151 Expect(result2.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5001"))) 152 }) 153 })