Skip to content

Commit

Permalink
add one arg example to test
Browse files Browse the repository at this point in the history
Signed-off-by: yeya24 <yb532204897@gmail.com>
  • Loading branch information
yeya24 committed Jun 6, 2019
1 parent aa0ae5f commit 8aaa5f4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 27 additions & 1 deletion test/cli_container_port_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package main

import (
"strings"

"github.com/alibaba/pouch/test/command"
"github.com/alibaba/pouch/test/environment"

"github.com/go-check/check"
"github.com/gotestyourself/gotestyourself/icmd"
)
Expand All @@ -21,7 +24,7 @@ func (suite *PouchContainerPortSuite) SetUpSuite(c *check.C) {
}

// Test pouch port
func (suite *PouchContainerCopySuite) TestPouchPort(c *check.C) {
func (suite *PouchContainerPortSuite) TestPouchPort(c *check.C) {
testcase1 := "8000:8000"
testcase2 := "10000:10000/udp"
testcase3 := "127.0.0.1:5000:5000"
Expand All @@ -44,7 +47,30 @@ func (suite *PouchContainerCopySuite) TestPouchPort(c *check.C) {
name, "8000").Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "0.0.0.0:8000\n")

// Test for only one arg.
ret = command.PouchRun("port",
name, "10000/udp").Assert(c, icmd.Success)
c.Assert(ret.Stdout(), check.Equals, "0.0.0.0:10000\n")

portBindingMap := map[string]string{
"10000/udp": "0.0.0.0:10000",
"5000/tcp": "127.0.0.1:5000",
"8000/tcp": "0.0.0.0:8000",
}
ret = command.PouchRun("port", name).Assert(c, icmd.Success)
lines := strings.Split(ret.Stdout(), "\n")
for _, l := range lines {
outputs := strings.Split(l, "->")
// filter out the last line
if len(outputs) < 2 {
continue
}
port := strings.TrimSpace(outputs[0])
actualPortBinding := strings.TrimSpace(outputs[1])
if expected, exist := portBindingMap[port]; exist {
c.Assert(expected, check.Equals, actualPortBinding)
} else {
c.Errorf("Port %s not exists for container %s", port, name)
}
}
}
2 changes: 1 addition & 1 deletion test/environment/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

var (
// PouchBinary is default binary
PouchBinary = "/usr/local/bin/pouch"
PouchBinary = "/home/yeya24/hub/gowork/alibaba/src/github.com/alibaba/pouch/cli/pouch"

// PouchdAddress is default pouchd address
PouchdAddress = "unix:///var/run/pouchd.sock"
Expand Down

0 comments on commit 8aaa5f4

Please sign in to comment.