Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -47,22 +47,20 @@ func (s *DockerCLILogsSuite) TestLogsContainerMuchBiggerThanPage(c *testing.T) {
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 | 49 |
func testLogsContainerPagination(c *testing.T, testLen int) {
|
| 50 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen))
|
|
| 51 |
- id := strings.TrimSpace(out) |
|
| 52 |
- dockerCmd(c, "wait", id) |
|
| 53 |
- out, _ = dockerCmd(c, "logs", id) |
|
| 50 |
+ id := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo -n = >> a.a; done; echo >> a.a; cat a.a", testLen)).Stdout()
|
|
| 51 |
+ id = strings.TrimSpace(id) |
|
| 52 |
+ cli.DockerCmd(c, "wait", id) |
|
| 53 |
+ out := cli.DockerCmd(c, "logs", id).Combined() |
|
| 54 | 54 |
assert.Equal(c, len(out), testLen+1) |
| 55 | 55 |
} |
| 56 | 56 |
|
| 57 | 57 |
func (s *DockerCLILogsSuite) TestLogsTimestamps(c *testing.T) {
|
| 58 | 58 |
testLen := 100 |
| 59 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen))
|
|
| 60 |
- |
|
| 61 |
- id := strings.TrimSpace(out) |
|
| 62 |
- dockerCmd(c, "wait", id) |
|
| 63 |
- |
|
| 64 |
- out, _ = dockerCmd(c, "logs", "-t", id) |
|
| 59 |
+ id := cli.DockerCmd(c, "run", "-d", "busybox", "sh", "-c", fmt.Sprintf("for i in $(seq 1 %d); do echo = >> a.a; done; cat a.a", testLen)).Stdout()
|
|
| 60 |
+ id = strings.TrimSpace(id) |
|
| 61 |
+ cli.DockerCmd(c, "wait", id) |
|
| 65 | 62 |
|
| 63 |
+ out := cli.DockerCmd(c, "logs", "-t", id).Combined() |
|
| 66 | 64 |
lines := strings.Split(out, "\n") |
| 67 | 65 |
|
| 68 | 66 |
assert.Equal(c, len(lines), testLen+1) |
| ... | ... |
@@ -138,7 +136,7 @@ func (s *DockerCLILogsSuite) TestLogsTail(c *testing.T) {
|
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
func (s *DockerCLILogsSuite) TestLogsFollowStopped(c *testing.T) {
|
| 141 |
- dockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") |
|
| 141 |
+ cli.DockerCmd(c, "run", "--name=test", "busybox", "echo", "hello") |
|
| 142 | 142 |
id := getIDByName(c, "test") |
| 143 | 143 |
|
| 144 | 144 |
logsCmd := exec.Command(dockerBinary, "logs", "-f", id) |
| ... | ... |
@@ -160,14 +158,14 @@ func (s *DockerCLILogsSuite) TestLogsFollowStopped(c *testing.T) {
|
| 160 | 160 |
|
| 161 | 161 |
func (s *DockerCLILogsSuite) TestLogsSince(c *testing.T) {
|
| 162 | 162 |
name := "testlogssince" |
| 163 |
- dockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done") |
|
| 164 |
- out, _ := dockerCmd(c, "logs", "-t", name) |
|
| 163 |
+ cli.DockerCmd(c, "run", "--name="+name, "busybox", "/bin/sh", "-c", "for i in $(seq 1 3); do sleep 2; echo log$i; done") |
|
| 164 |
+ out := cli.DockerCmd(c, "logs", "-t", name).Combined() |
|
| 165 | 165 |
|
| 166 | 166 |
log2Line := strings.Split(strings.Split(out, "\n")[1], " ") |
| 167 | 167 |
t, err := time.Parse(time.RFC3339Nano, log2Line[0]) // the timestamp log2 is written |
| 168 | 168 |
assert.NilError(c, err) |
| 169 | 169 |
since := t.Unix() + 1 // add 1s so log1 & log2 doesn't show up |
| 170 |
- out, _ = dockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name)
|
|
| 170 |
+ out = cli.DockerCmd(c, "logs", "-t", fmt.Sprintf("--since=%v", since), name).Combined()
|
|
| 171 | 171 |
|
| 172 | 172 |
// Skip 2 seconds |
| 173 | 173 |
unexpected := []string{"log1", "log2"}
|
| ... | ... |
@@ -197,14 +195,14 @@ func (s *DockerCLILogsSuite) TestLogsSinceFutureFollow(c *testing.T) {
|
| 197 | 197 |
// TODO Windows TP5 - Figure out why this test is so flakey. Disabled for now. |
| 198 | 198 |
testRequires(c, DaemonIsLinux) |
| 199 | 199 |
name := "testlogssincefuturefollow" |
| 200 |
- dockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`) |
|
| 200 |
+ cli.DockerCmd(c, "run", "-d", "--name", name, "busybox", "/bin/sh", "-c", `for i in $(seq 1 5); do echo log$i; sleep 1; done`) |
|
| 201 | 201 |
|
| 202 | 202 |
// Extract one timestamp from the log file to give us a starting point for |
| 203 | 203 |
// our `--since` argument. Because the log producer runs in the background, |
| 204 | 204 |
// we need to check repeatedly for some output to be produced. |
| 205 | 205 |
var timestamp string |
| 206 | 206 |
for i := 0; i != 100 && timestamp == ""; i++ {
|
| 207 |
- if out, _ := dockerCmd(c, "logs", "-t", name); out == "" {
|
|
| 207 |
+ if out := cli.DockerCmd(c, "logs", "-t", name).Combined(); out == "" {
|
|
| 208 | 208 |
time.Sleep(time.Millisecond * 100) // Retry |
| 209 | 209 |
} else {
|
| 210 | 210 |
timestamp = strings.Split(strings.Split(out, "\n")[0], " ")[0] |
| ... | ... |
@@ -216,7 +214,7 @@ func (s *DockerCLILogsSuite) TestLogsSinceFutureFollow(c *testing.T) {
|
| 216 | 216 |
assert.NilError(c, err) |
| 217 | 217 |
|
| 218 | 218 |
since := t.Unix() + 2 |
| 219 |
- out, _ := dockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name)
|
|
| 219 |
+ out := cli.DockerCmd(c, "logs", "-t", "-f", fmt.Sprintf("--since=%v", since), name).Combined()
|
|
| 220 | 220 |
assert.Assert(c, len(out) != 0, "cannot read from empty log") |
| 221 | 221 |
lines := strings.Split(strings.TrimSpace(out), "\n") |
| 222 | 222 |
for _, v := range lines {
|
| ... | ... |
@@ -231,14 +229,13 @@ func (s *DockerCLILogsSuite) TestLogsFollowSlowStdoutConsumer(c *testing.T) {
|
| 231 | 231 |
// TODO Windows: Fix this test for TP5. |
| 232 | 232 |
testRequires(c, DaemonIsLinux) |
| 233 | 233 |
expected := 150000 |
| 234 |
- out, _ := dockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", fmt.Sprintf("usleep 600000; yes X | head -c %d", expected))
|
|
| 235 |
- |
|
| 236 |
- id := strings.TrimSpace(out) |
|
| 234 |
+ id := cli.DockerCmd(c, "run", "-d", "busybox", "/bin/sh", "-c", fmt.Sprintf("usleep 600000; yes X | head -c %d", expected)).Stdout()
|
|
| 235 |
+ id = strings.TrimSpace(id) |
|
| 237 | 236 |
|
| 238 | 237 |
stopSlowRead := make(chan bool) |
| 239 | 238 |
|
| 240 | 239 |
go func() {
|
| 241 |
- dockerCmd(c, "wait", id) |
|
| 240 |
+ cli.DockerCmd(c, "wait", id) |
|
| 242 | 241 |
stopSlowRead <- true |
| 243 | 242 |
}() |
| 244 | 243 |
|
| ... | ... |
@@ -389,8 +386,8 @@ func (s *DockerCLILogsSuite) TestLogsCLIContainerNotFound(c *testing.T) {
|
| 389 | 389 |
} |
| 390 | 390 |
|
| 391 | 391 |
func (s *DockerCLILogsSuite) TestLogsWithDetails(c *testing.T) {
|
| 392 |
- dockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello") |
|
| 393 |
- out, _ := dockerCmd(c, "logs", "--details", "--timestamps", "test") |
|
| 392 |
+ cli.DockerCmd(c, "run", "--name=test", "--label", "foo=bar", "-e", "baz=qux", "--log-opt", "labels=foo", "--log-opt", "env=baz", "busybox", "echo", "hello") |
|
| 393 |
+ out := cli.DockerCmd(c, "logs", "--details", "--timestamps", "test").Combined() |
|
| 394 | 394 |
|
| 395 | 395 |
logFields := strings.Fields(strings.TrimSpace(out)) |
| 396 | 396 |
assert.Equal(c, len(logFields), 3, out) |