2015-04-11 17:49:14 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"os/exec"
|
2015-04-18 12:46:47 -04:00
|
|
|
|
|
|
|
"github.com/go-check/check"
|
2015-04-11 17:49:14 -04:00
|
|
|
)
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLogsApiWithStdout(c *check.C) {
|
2015-04-11 17:49:14 -04:00
|
|
|
name := "logs_test"
|
|
|
|
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "bin/sh", "-c", "sleep 10 && echo "+name)
|
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1×tamps=1", name), nil)
|
|
|
|
|
|
|
|
if err != nil || statusCode != http.StatusOK {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %d from logs request, got %d", http.StatusOK, statusCode)
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if !bytes.Contains(body, []byte(name)) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %s, got %s", name, string(body[:]))
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-18 12:46:47 -04:00
|
|
|
func (s *DockerSuite) TestLogsApiNoStdoutNorStderr(c *check.C) {
|
2015-04-11 17:49:14 -04:00
|
|
|
name := "logs_test"
|
|
|
|
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
|
|
|
|
if out, _, err := runCommandWithOutput(runCmd); err != nil {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatal(out, err)
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
|
|
|
|
|
|
|
|
if err == nil || statusCode != http.StatusBadRequest {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %d from logs request, got %d", http.StatusBadRequest, statusCode)
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
expected := "Bad parameters: you must choose at least one stream"
|
|
|
|
if !bytes.Contains(body, []byte(expected)) {
|
2015-04-18 12:46:47 -04:00
|
|
|
c.Fatalf("Expected %s, got %s", expected, string(body[:]))
|
2015-04-11 17:49:14 -04:00
|
|
|
}
|
|
|
|
}
|