github.com/containers/podman/v5@v5.1.0-rc1/test/e2e/port_test.go (about) 1 package integration 2 3 import ( 4 "fmt" 5 "strings" 6 7 . "github.com/containers/podman/v5/test/utils" 8 . "github.com/onsi/ginkgo/v2" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Podman port", func() { 13 14 It("podman port all and latest", func() { 15 result := podmanTest.Podman([]string{"port", "-a", "-l"}) 16 result.WaitWithDefaultTimeout() 17 if IsRemote() { 18 Expect(result).To(ExitWithError(125, "unknown shorthand flag: 'l' in -l")) 19 } else { 20 Expect(result).To(ExitWithError(125, "--all and --latest cannot be used together")) 21 } 22 }) 23 24 It("podman port all and extra", func() { 25 result := podmanTest.Podman([]string{"port", "-a", "foobar"}) 26 result.WaitWithDefaultTimeout() 27 Expect(result).To(ExitWithError(125, "no arguments are needed with --all")) 28 }) 29 30 It("podman port -l nginx", func() { 31 session, cid := podmanTest.RunNginxWithHealthCheck("test1") 32 Expect(session).Should(ExitCleanly()) 33 34 if err := podmanTest.RunHealthCheck(cid); err != nil { 35 Fail(err.Error()) 36 } 37 38 if !IsRemote() { 39 cid = "-l" 40 } 41 result := podmanTest.Podman([]string{"port", cid}) 42 result.WaitWithDefaultTimeout() 43 Expect(result).Should(ExitCleanly()) 44 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 45 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) 46 }) 47 48 It("podman container port -l nginx", func() { 49 session, cid := podmanTest.RunNginxWithHealthCheck("") 50 Expect(session).Should(ExitCleanly()) 51 52 if err := podmanTest.RunHealthCheck(cid); err != nil { 53 Fail(err.Error()) 54 } 55 56 if !IsRemote() { 57 cid = "-l" 58 } 59 result := podmanTest.Podman([]string{"container", "port", cid}) 60 result.WaitWithDefaultTimeout() 61 Expect(result).Should(ExitCleanly()) 62 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 63 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port)))) 64 }) 65 66 It("podman port -l port nginx", func() { 67 session, cid := podmanTest.RunNginxWithHealthCheck("") 68 Expect(session).Should(ExitCleanly()) 69 70 if err := podmanTest.RunHealthCheck(cid); err != nil { 71 Fail(err.Error()) 72 } 73 74 if !IsRemote() { 75 cid = "-l" 76 } 77 result := podmanTest.Podman([]string{"port", cid, "80"}) 78 result.WaitWithDefaultTimeout() 79 Expect(result).Should(ExitCleanly()) 80 port := strings.Split(result.OutputToStringArray()[0], ":")[1] 81 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix(fmt.Sprintf("0.0.0.0:%s", port)))) 82 }) 83 84 It("podman port -a nginx", func() { 85 session, cid := podmanTest.RunNginxWithHealthCheck("") 86 Expect(session).Should(ExitCleanly()) 87 88 if err := podmanTest.RunHealthCheck(cid); err != nil { 89 Fail(err.Error()) 90 } 91 92 result := podmanTest.Podman([]string{"port", "-a"}) 93 result.WaitWithDefaultTimeout() 94 Expect(result).Should(ExitCleanly()) 95 }) 96 97 It("podman port nginx by name", func() { 98 session, cid := podmanTest.RunNginxWithHealthCheck("portcheck") 99 Expect(session).Should(ExitCleanly()) 100 101 if err := podmanTest.RunHealthCheck(cid); err != nil { 102 Fail(err.Error()) 103 } 104 105 result := podmanTest.Podman([]string{"port", "portcheck"}) 106 result.WaitWithDefaultTimeout() 107 Expect(result).Should(ExitCleanly()) 108 Expect(result.OutputToStringArray()).To(ContainElement(HavePrefix("80/tcp -> 0.0.0.0:"))) 109 }) 110 111 It("podman port multiple ports", func() { 112 // Acquire and release locks 113 lock1 := GetPortLock("5010") 114 defer lock1.Unlock() 115 lock2 := GetPortLock("5011") 116 defer lock2.Unlock() 117 118 setup := podmanTest.Podman([]string{"run", "--name", "test", "-dt", "-p", "5010:5000", "-p", "5011:5001", ALPINE, "top"}) 119 setup.WaitWithDefaultTimeout() 120 Expect(setup).Should(ExitCleanly()) 121 122 // Check that the first port was honored 123 result1 := podmanTest.Podman([]string{"port", "test", "5000"}) 124 result1.WaitWithDefaultTimeout() 125 Expect(result1).Should(ExitCleanly()) 126 Expect(result1.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5010"))) 127 128 // Check that the second port was honored 129 result2 := podmanTest.Podman([]string{"port", "test", "5001"}) 130 result2.WaitWithDefaultTimeout() 131 Expect(result2).Should(ExitCleanly()) 132 Expect(result2.OutputToStringArray()).To(ContainElement(HavePrefix("0.0.0.0:5011"))) 133 }) 134 })