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

     1  package integration
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	. "github.com/containers/podman/v3/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  		podmanTest.SeedImages()
    29  	})
    30  
    31  	AfterEach(func() {
    32  		podmanTest.Cleanup()
    33  		f := CurrentGinkgoTestDescription()
    34  		processTestResult(f)
    35  
    36  	})
    37  
    38  	It("podman port all and latest", func() {
    39  		result := podmanTest.Podman([]string{"port", "-a", "-l"})
    40  		result.WaitWithDefaultTimeout()
    41  		Expect(result).To(ExitWithError())
    42  	})
    43  
    44  	It("podman port all and extra", func() {
    45  		result := podmanTest.Podman([]string{"port", "-a", "foobar"})
    46  		result.WaitWithDefaultTimeout()
    47  		Expect(result).To(ExitWithError())
    48  	})
    49  
    50  	It("podman port -l nginx", func() {
    51  		session, cid := podmanTest.RunNginxWithHealthCheck("test1")
    52  		Expect(session).Should(Exit(0))
    53  
    54  		if err := podmanTest.RunHealthCheck(cid); err != nil {
    55  			Fail(err.Error())
    56  		}
    57  
    58  		if !IsRemote() {
    59  			cid = "-l"
    60  		}
    61  		result := podmanTest.Podman([]string{"port", cid})
    62  		result.WaitWithDefaultTimeout()
    63  		Expect(result).Should(Exit(0))
    64  		port := strings.Split(result.OutputToStringArray()[0], ":")[1]
    65  		Expect(result.LineInOutputStartsWith(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port))).To(BeTrue())
    66  	})
    67  
    68  	It("podman container port  -l nginx", func() {
    69  		session, cid := podmanTest.RunNginxWithHealthCheck("")
    70  		Expect(session).Should(Exit(0))
    71  
    72  		if err := podmanTest.RunHealthCheck(cid); err != nil {
    73  			Fail(err.Error())
    74  		}
    75  
    76  		if !IsRemote() {
    77  			cid = "-l"
    78  		}
    79  		result := podmanTest.Podman([]string{"container", "port", cid})
    80  		result.WaitWithDefaultTimeout()
    81  		Expect(result).Should(Exit(0))
    82  		port := strings.Split(result.OutputToStringArray()[0], ":")[1]
    83  		Expect(result.LineInOutputStartsWith(fmt.Sprintf("80/tcp -> 0.0.0.0:%s", port))).To(BeTrue())
    84  	})
    85  
    86  	It("podman port -l port nginx", func() {
    87  		session, cid := podmanTest.RunNginxWithHealthCheck("")
    88  		Expect(session).Should(Exit(0))
    89  
    90  		if err := podmanTest.RunHealthCheck(cid); err != nil {
    91  			Fail(err.Error())
    92  		}
    93  
    94  		if !IsRemote() {
    95  			cid = "-l"
    96  		}
    97  		result := podmanTest.Podman([]string{"port", cid, "80"})
    98  		result.WaitWithDefaultTimeout()
    99  		Expect(result).Should(Exit(0))
   100  		port := strings.Split(result.OutputToStringArray()[0], ":")[1]
   101  		Expect(result.LineInOutputStartsWith(fmt.Sprintf("0.0.0.0:%s", port))).To(BeTrue())
   102  	})
   103  
   104  	It("podman port -a nginx", func() {
   105  		session, cid := podmanTest.RunNginxWithHealthCheck("")
   106  		Expect(session).Should(Exit(0))
   107  
   108  		if err := podmanTest.RunHealthCheck(cid); err != nil {
   109  			Fail(err.Error())
   110  		}
   111  
   112  		result := podmanTest.Podman([]string{"port", "-a"})
   113  		result.WaitWithDefaultTimeout()
   114  		Expect(result).Should(Exit(0))
   115  	})
   116  
   117  	It("podman port nginx by name", func() {
   118  		session, cid := podmanTest.RunNginxWithHealthCheck("portcheck")
   119  		Expect(session).Should(Exit(0))
   120  
   121  		if err := podmanTest.RunHealthCheck(cid); err != nil {
   122  			Fail(err.Error())
   123  		}
   124  
   125  		result := podmanTest.Podman([]string{"port", "portcheck"})
   126  		result.WaitWithDefaultTimeout()
   127  		Expect(result).Should(Exit(0))
   128  		result.LineInOutputStartsWith("80/tcp -> 0.0.0.0:")
   129  	})
   130  
   131  	It("podman port multiple ports", func() {
   132  		// Acquire and release locks
   133  		lock1 := GetPortLock("5000")
   134  		defer lock1.Unlock()
   135  		lock2 := GetPortLock("5001")
   136  		defer lock2.Unlock()
   137  
   138  		setup := podmanTest.Podman([]string{"run", "--name", "test", "-dt", "-p", "5000:5000", "-p", "5001:5001", ALPINE, "top"})
   139  		setup.WaitWithDefaultTimeout()
   140  		Expect(setup).Should(Exit(0))
   141  
   142  		// Check that the first port was honored
   143  		result1 := podmanTest.Podman([]string{"port", "test", "5000"})
   144  		result1.WaitWithDefaultTimeout()
   145  		Expect(result1).Should(Exit(0))
   146  		Expect(result1.LineInOutputStartsWith("0.0.0.0:5000")).To(BeTrue())
   147  
   148  		// Check that the second port was honored
   149  		result2 := podmanTest.Podman([]string{"port", "test", "5001"})
   150  		result2.WaitWithDefaultTimeout()
   151  		Expect(result2).Should(Exit(0))
   152  		Expect(result2.LineInOutputStartsWith("0.0.0.0:5001")).To(BeTrue())
   153  	})
   154  })