Begin to copy the data until the command to exit and any coping to
stdin or copy from stdout/stderr has completed.
Also adding defense code to trim the possible '\x00' null value.
Signed-off-by: Dennis Chen <dennis.chen@arm.com>
| ... | ... |
@@ -25,10 +25,6 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
|
| 25 | 25 |
c.Assert(err, checker.IsNil) |
| 26 | 26 |
|
| 27 | 27 |
b := bytes.NewBuffer(nil) |
| 28 |
- go func() {
|
|
| 29 |
- io.Copy(b, p) |
|
| 30 |
- p.Close() |
|
| 31 |
- }() |
|
| 32 | 28 |
|
| 33 | 29 |
ch := make(chan error) |
| 34 | 30 |
go func() { ch <- cmd.Wait() }()
|
| ... | ... |
@@ -36,9 +32,14 @@ func (s *DockerSuite) TestExecInteractiveStdinClose(c *check.C) {
|
| 36 | 36 |
select {
|
| 37 | 37 |
case err := <-ch: |
| 38 | 38 |
c.Assert(err, checker.IsNil) |
| 39 |
- output := b.String() |
|
| 39 |
+ io.Copy(b, p) |
|
| 40 |
+ p.Close() |
|
| 41 |
+ bs := b.Bytes() |
|
| 42 |
+ bs = bytes.Trim(bs, "\x00") |
|
| 43 |
+ output := string(bs[:]) |
|
| 40 | 44 |
c.Assert(strings.TrimSpace(output), checker.Equals, "hello") |
| 41 | 45 |
case <-time.After(5 * time.Second): |
| 46 |
+ p.Close() |
|
| 42 | 47 |
c.Fatal("timed out running docker exec")
|
| 43 | 48 |
} |
| 44 | 49 |
} |