Skip to content

Commit 8aaa5f4

Browse files
committed
add one arg example to test
Signed-off-by: yeya24 <[email protected]>
1 parent aa0ae5f commit 8aaa5f4

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

test/cli_container_port_test.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package main
22

33
import (
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
}

test/environment/env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414

1515
var (
1616
// PouchBinary is default binary
17-
PouchBinary = "/usr/local/bin/pouch"
17+
PouchBinary = "/home/yeya24/hub/gowork/alibaba/src/github.com/alibaba/pouch/cli/pouch"
1818

1919
// PouchdAddress is default pouchd address
2020
PouchdAddress = "unix:///var/run/pouchd.sock"

0 commit comments

Comments
 (0)