1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Cleaned up integration-cli/docker_api_logs_test.go

Signed-off-by: Zachary Jaffee <zij@case.edu>
This commit is contained in:
Zachary Jaffee 2015-10-15 13:33:31 -04:00
parent 9216b08536
commit 7aab43e8d4

View file

@ -8,6 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check" "github.com/go-check/check"
) )
@ -15,7 +16,7 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
testRequires(c, DaemonIsLinux) testRequires(c, DaemonIsLinux)
out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done") out, _ := dockerCmd(c, "run", "-d", "-t", "busybox", "/bin/sh", "-c", "while true; do echo hello; sleep 1; done")
id := strings.TrimSpace(out) id := strings.TrimSpace(out)
c.Assert(waitRun(id), check.IsNil) c.Assert(waitRun(id), checker.IsNil)
type logOut struct { type logOut struct {
out string out string
@ -41,8 +42,8 @@ func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
select { select {
case l := <-chLog: case l := <-chLog:
c.Assert(l.err, check.IsNil) c.Assert(l.err, checker.IsNil)
c.Assert(l.res.StatusCode, check.Equals, http.StatusOK) c.Assert(l.res.StatusCode, checker.Equals, http.StatusOK)
if !strings.HasSuffix(l.out, "hello") { if !strings.HasSuffix(l.out, "hello") {
c.Fatalf("expected log output to container 'hello', but it does not") c.Fatalf("expected log output to container 'hello', but it does not")
} }
@ -57,8 +58,8 @@ func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh") dockerCmd(c, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil) status, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
c.Assert(status, check.Equals, http.StatusBadRequest) c.Assert(status, checker.Equals, http.StatusBadRequest)
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
expected := "Bad parameters: you must choose at least one stream" expected := "Bad parameters: you must choose at least one stream"
if !bytes.Contains(body, []byte(expected)) { if !bytes.Contains(body, []byte(expected)) {
@ -75,7 +76,7 @@ func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) {
_, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "") _, body, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
t1 := time.Now() t1 := time.Now()
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
body.Close() body.Close()
elapsed := t1.Sub(t0).Seconds() elapsed := t1.Sub(t0).Seconds()
if elapsed > 5.0 { if elapsed > 5.0 {
@ -86,6 +87,6 @@ func (s *DockerSuite) TestLogsApiFollowEmptyOutput(c *check.C) {
func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) { func (s *DockerSuite) TestLogsAPIContainerNotFound(c *check.C) {
name := "nonExistentContainer" name := "nonExistentContainer"
resp, _, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "") resp, _, err := sockRequestRaw("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&stderr=1&tail=all", name), bytes.NewBuffer(nil), "")
c.Assert(err, check.IsNil) c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, check.Equals, http.StatusNotFound) c.Assert(resp.StatusCode, checker.Equals, http.StatusNotFound)
} }