Signed-off-by: Darren Shepherd <darren@rancher.com>
| ... | ... |
@@ -9,6 +9,7 @@ import ( |
| 9 | 9 |
"net/http/httputil" |
| 10 | 10 |
"os" |
| 11 | 11 |
"os/exec" |
| 12 |
+ "strconv" |
|
| 12 | 13 |
"strings" |
| 13 | 14 |
"time" |
| 14 | 15 |
|
| ... | ... |
@@ -84,6 +85,45 @@ func (s *DockerSuite) TestContainerApiGetJSONNoFieldsOmitted(c *check.C) {
|
| 84 | 84 |
} |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
+type containerPs struct {
|
|
| 88 |
+ Names []string |
|
| 89 |
+ Ports []map[string]interface{}
|
|
| 90 |
+} |
|
| 91 |
+ |
|
| 92 |
+// regression test for non-empty fields from #13901 |
|
| 93 |
+func (s *DockerSuite) TestContainerPsOmitFields(c *check.C) {
|
|
| 94 |
+ name := "pstest" |
|
| 95 |
+ port := 80 |
|
| 96 |
+ runCmd := exec.Command(dockerBinary, "run", "-d", "--name", name, "--expose", strconv.Itoa(port), "busybox", "sleep", "5") |
|
| 97 |
+ _, err := runCommand(runCmd) |
|
| 98 |
+ c.Assert(err, check.IsNil) |
|
| 99 |
+ |
|
| 100 |
+ status, body, err := sockRequest("GET", "/containers/json?all=1", nil)
|
|
| 101 |
+ c.Assert(status, check.Equals, http.StatusOK) |
|
| 102 |
+ c.Assert(err, check.IsNil) |
|
| 103 |
+ |
|
| 104 |
+ var resp []containerPs |
|
| 105 |
+ err = json.Unmarshal(body, &resp) |
|
| 106 |
+ c.Assert(err, check.IsNil) |
|
| 107 |
+ |
|
| 108 |
+ var foundContainer *containerPs |
|
| 109 |
+ for _, container := range resp {
|
|
| 110 |
+ for _, testName := range container.Names {
|
|
| 111 |
+ if "/"+name == testName {
|
|
| 112 |
+ foundContainer = &container |
|
| 113 |
+ break |
|
| 114 |
+ } |
|
| 115 |
+ } |
|
| 116 |
+ } |
|
| 117 |
+ |
|
| 118 |
+ c.Assert(len(foundContainer.Ports), check.Equals, 1) |
|
| 119 |
+ c.Assert(foundContainer.Ports[0]["PrivatePort"], check.Equals, float64(port)) |
|
| 120 |
+ _, ok := foundContainer.Ports[0]["PublicPort"] |
|
| 121 |
+ c.Assert(ok, check.Not(check.Equals), true) |
|
| 122 |
+ _, ok = foundContainer.Ports[0]["IP"] |
|
| 123 |
+ c.Assert(ok, check.Not(check.Equals), true) |
|
| 124 |
+} |
|
| 125 |
+ |
|
| 87 | 126 |
func (s *DockerSuite) TestContainerApiGetExport(c *check.C) {
|
| 88 | 127 |
name := "exportcontainer" |
| 89 | 128 |
runCmd := exec.Command(dockerBinary, "run", "--name", name, "busybox", "touch", "/test") |