11package main
22
33import (
4+ "strings"
5+
46 "github.com/alibaba/pouch/test/command"
57 "github.com/alibaba/pouch/test/environment"
8+
69 "github.com/go-check/check"
710 "github.com/gotestyourself/gotestyourself/icmd"
811)
@@ -21,7 +24,7 @@ func (suite *PouchContainerPortSuite) SetUpSuite(c *check.C) {
2124}
2225
2326// Test pouch port
24- func (suite * PouchContainerCopySuite ) TestPouchPort (c * check.C ) {
27+ func (suite * PouchContainerPortSuite ) TestPouchPort (c * check.C ) {
2528 testcase1 := "8000:8000"
2629 testcase2 := "10000:10000/udp"
2730 testcase3 := "127.0.0.1:5000:5000"
@@ -44,7 +47,30 @@ func (suite *PouchContainerCopySuite) TestPouchPort(c *check.C) {
4447 name , "8000" ).Assert (c , icmd .Success )
4548 c .Assert (ret .Stdout (), check .Equals , "0.0.0.0:8000\n " )
4649
50+ // Test for only one arg.
4751 ret = command .PouchRun ("port" ,
4852 name , "10000/udp" ).Assert (c , icmd .Success )
4953 c .Assert (ret .Stdout (), check .Equals , "0.0.0.0:10000\n " )
54+
55+ portBindingMap := map [string ]string {
56+ "10000/udp" : "0.0.0.0:10000" ,
57+ "5000/tcp" : "127.0.0.1:5000" ,
58+ "8000/tcp" : "0.0.0.0:8000" ,
59+ }
60+ ret = command .PouchRun ("port" , name ).Assert (c , icmd .Success )
61+ lines := strings .Split (ret .Stdout (), "\n " )
62+ for _ , l := range lines {
63+ outputs := strings .Split (l , "->" )
64+ // filter out the last line
65+ if len (outputs ) < 2 {
66+ continue
67+ }
68+ port := strings .TrimSpace (outputs [0 ])
69+ actualPortBinding := strings .TrimSpace (outputs [1 ])
70+ if expected , exist := portBindingMap [port ]; exist {
71+ c .Assert (expected , check .Equals , actualPortBinding )
72+ } else {
73+ c .Errorf ("Port %s not exists for container %s" , port , name )
74+ }
75+ }
5076}
0 commit comments