Remove job from logs

Signed-off-by: Antonio Murdaca <me@runcom.ninja>
Upstream-commit: 91bfed604959c591a076c2e330cb3ded7443f504
Component: engine
This commit is contained in:
Antonio Murdaca
2015-04-13 08:25:31 +02:00
parent 6fd02194d0
commit b3c5a7d38d
13 changed files with 151 additions and 197 deletions
@@ -3,14 +3,15 @@ package main
import (
"bytes"
"encoding/json"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
"io"
"os/exec"
"strings"
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
)
func TestContainerApiGetAll(t *testing.T) {
@@ -28,7 +29,7 @@ func TestContainerApiGetAll(t *testing.T) {
t.Fatalf("Error on container creation: %v, output: %q", err, out)
}
body, err := sockRequest("GET", "/containers/json?all=1", nil)
_, body, err := sockRequest("GET", "/containers/json?all=1", nil)
if err != nil {
t.Fatalf("GET all containers sockRequest failed: %v", err)
}
@@ -61,7 +62,7 @@ func TestContainerApiGetExport(t *testing.T) {
t.Fatalf("Error on container creation: %v, output: %q", err, out)
}
body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
_, body, err := sockRequest("GET", "/containers/"+name+"/export", nil)
if err != nil {
t.Fatalf("GET containers/export sockRequest failed: %v", err)
}
@@ -98,7 +99,7 @@ func TestContainerApiGetChanges(t *testing.T) {
t.Fatalf("Error on container creation: %v, output: %q", err, out)
}
body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
_, body, err := sockRequest("GET", "/containers/"+name+"/changes", nil)
if err != nil {
t.Fatalf("GET containers/changes sockRequest failed: %v", err)
}
@@ -133,7 +134,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
"Volumes": map[string]struct{}{"/tmp": {}},
}
if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
t.Fatal(err)
}
@@ -141,7 +142,7 @@ func TestContainerApiStartVolumeBinds(t *testing.T) {
config = map[string]interface{}{
"Binds": []string{bindPath + ":/tmp"},
}
if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatal(err)
}
@@ -166,7 +167,7 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
"Volumes": map[string]struct{}{"/tmp": {}},
}
if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
t.Fatal(err)
}
@@ -176,7 +177,7 @@ func TestContainerApiStartDupVolumeBinds(t *testing.T) {
config = map[string]interface{}{
"Binds": []string{bindPath1 + ":/tmp", bindPath2 + ":/tmp"},
}
if body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
if _, body, err := sockRequest("POST", "/containers/"+name+"/start", config); err == nil {
t.Fatal("expected container start to fail when duplicate volume binds to same container path")
} else {
if !strings.Contains(string(body), "Duplicate volume") {
@@ -201,14 +202,14 @@ func TestContainerApiStartVolumesFrom(t *testing.T) {
"Volumes": map[string]struct{}{volPath: {}},
}
if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
t.Fatal(err)
}
config = map[string]interface{}{
"VolumesFrom": []string{volName},
}
if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatal(err)
}
@@ -245,7 +246,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
"Volumes": map[string]struct{}{volPath: {}},
}
if _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
if _, _, err := sockRequest("POST", "/containers/create?name="+name, config); err != nil && !strings.Contains(err.Error(), "201 Created") {
t.Fatal(err)
}
@@ -254,7 +255,7 @@ func TestVolumesFromHasPriority(t *testing.T) {
"VolumesFrom": []string{volName},
"Binds": []string{bindPath + ":/tmp"},
}
if _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
if _, _, err := sockRequest("POST", "/containers/"+name+"/start", config); err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatal(err)
}
@@ -290,7 +291,7 @@ func TestGetContainerStats(t *testing.T) {
}
bc := make(chan b, 1)
go func() {
body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
_, body, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
bc <- b{body, err}
}()
@@ -334,7 +335,7 @@ func TestGetStoppedContainerStats(t *testing.T) {
go func() {
// We'll never get return for GET stats from sockRequest as of now,
// just send request and see if panic or error would happen on daemon side.
_, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
_, _, err := sockRequest("GET", "/containers/"+name+"/stats", nil)
if err != nil {
t.Fatal(err)
}
@@ -367,7 +368,7 @@ func TestBuildApiDockerfilePath(t *testing.T) {
t.Fatalf("failed to close tar archive: %v", err)
}
out, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
_, out, err := sockRequestRaw("POST", "/build?dockerfile=../Dockerfile", buffer, "application/x-tar")
if err == nil {
t.Fatalf("Build was supposed to fail: %s", out)
}
@@ -391,7 +392,7 @@ RUN find /tmp/`,
}
defer server.Close()
buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
_, buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+server.URL()+"/testD", nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s", err)
}
@@ -417,7 +418,7 @@ RUN echo from dockerfile`,
}
defer git.Close()
buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
_, buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s\n%q", err, buf)
}
@@ -443,7 +444,7 @@ RUN echo from Dockerfile`,
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
_, buf, err := sockRequestRaw("POST", "/build?dockerfile=baz&remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s\n%q", err, buf)
}
@@ -470,7 +471,7 @@ RUN echo from dockerfile`,
defer git.Close()
// Make sure it tries to 'dockerfile' query param value
buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
_, buf, err := sockRequestRaw("POST", "/build?remote="+git.RepoURL, nil, "application/json")
if err != nil {
t.Fatalf("Build failed: %s", err)
}
@@ -501,7 +502,7 @@ func TestBuildApiDockerfileSymlink(t *testing.T) {
t.Fatalf("failed to close tar archive: %v", err)
}
out, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
_, out, err := sockRequestRaw("POST", "/build", buffer, "application/x-tar")
if err == nil {
t.Fatalf("Build was supposed to fail: %s", out)
}
@@ -537,7 +538,7 @@ func TestPostContainerBindNormalVolume(t *testing.T) {
}
bindSpec := map[string][]string{"Binds": {fooDir + ":/foo"}}
_, err = sockRequest("POST", "/containers/two/start", bindSpec)
_, _, err = sockRequest("POST", "/containers/two/start", bindSpec)
if err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatal(err)
}
@@ -565,7 +566,7 @@ func TestContainerApiPause(t *testing.T) {
}
ContainerID := strings.TrimSpace(out)
if _, err = sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
if _, _, err = sockRequest("POST", "/containers/"+ContainerID+"/pause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
}
@@ -579,7 +580,7 @@ func TestContainerApiPause(t *testing.T) {
t.Fatalf("there should be one paused container and not %d", len(pausedContainers))
}
if _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
if _, _, err = sockRequest("POST", "/containers/"+ContainerID+"/unpause", nil); err != nil && !strings.Contains(err.Error(), "204 No Content") {
t.Fatalf("POST a container pause: sockRequest failed: %v", err)
}
@@ -18,7 +18,7 @@ func TestExecApiCreateNoCmd(t *testing.T) {
t.Fatal(out, err)
}
body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
_, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), map[string]interface{}{"Cmd": nil})
if err == nil || !bytes.Contains(body, []byte("No exec command specified")) {
t.Fatalf("Expected error when creating exec command with no Cmd specified: %q", err)
}
@@ -8,7 +8,7 @@ import (
)
func TestLegacyImages(t *testing.T) {
body, err := sockRequest("GET", "/v1.6/images/json", nil)
_, body, err := sockRequest("GET", "/v1.6/images/json", nil)
if err != nil {
t.Fatalf("Error on GET: %s", err)
}
@@ -27,7 +27,7 @@ func TestInspectApiContainerResponse(t *testing.T) {
if testVersion != "latest" {
endpoint = "/" + testVersion + endpoint
}
body, err := sockRequest("GET", endpoint, nil)
_, body, err := sockRequest("GET", endpoint, nil)
if err != nil {
t.Fatalf("sockRequest failed for %s version: %v", testVersion, err)
}
@@ -0,0 +1,53 @@
package main
import (
"bytes"
"fmt"
"net/http"
"os/exec"
"testing"
)
func TestLogsApiWithStdout(t *testing.T) {
defer deleteAllContainers()
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 {
t.Fatal(out, err)
}
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs?follow=1&stdout=1&timestamps=1", name), nil)
if err != nil || statusCode != http.StatusOK {
t.Fatalf("Expected %d from logs request, got %d", http.StatusOK, statusCode)
}
if !bytes.Contains(body, []byte(name)) {
t.Fatalf("Expected %s, got %s", name, string(body[:]))
}
logDone("logs API - with stdout ok")
}
func TestLogsApiNoStdoutNorStderr(t *testing.T) {
defer deleteAllContainers()
name := "logs_test"
runCmd := exec.Command(dockerBinary, "run", "-d", "-t", "--name", name, "busybox", "/bin/sh")
if out, _, err := runCommandWithOutput(runCmd); err != nil {
t.Fatal(out, err)
}
statusCode, body, err := sockRequest("GET", fmt.Sprintf("/containers/%s/logs", name), nil)
if err == nil || statusCode != http.StatusBadRequest {
t.Fatalf("Expected %d from logs request, got %d", http.StatusBadRequest, statusCode)
}
expected := "Bad parameters: you must choose at least one stream"
if !bytes.Contains(body, []byte(expected)) {
t.Fatalf("Expected %s, got %s", expected, string(body[:]))
}
logDone("logs API - returns error when no stdout nor stderr specified")
}
@@ -16,7 +16,7 @@ func TestResizeApiResponse(t *testing.T) {
cleanedContainerID := strings.TrimSpace(out)
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
_, err = sockRequest("POST", endpoint, nil)
_, _, err = sockRequest("POST", endpoint, nil)
if err != nil {
t.Fatalf("resize Request failed %v", err)
}
@@ -41,7 +41,7 @@ func TestResizeApiResponseWhenContainerNotStarted(t *testing.T) {
}
endpoint := "/containers/" + cleanedContainerID + "/resize?h=40&w=40"
body, err := sockRequest("POST", endpoint, nil)
_, body, err := sockRequest("POST", endpoint, nil)
if err == nil {
t.Fatalf("resize should fail when container is not started")
}
@@ -64,7 +64,7 @@ func TestRmRunningContainerCheckError409(t *testing.T) {
createRunningContainer(t, "foo")
endpoint := "/containers/foo"
_, err := sockRequest("DELETE", endpoint, nil)
_, _, err := sockRequest("DELETE", endpoint, nil)
if err == nil {
t.Fatalf("Expected error, can't rm a running container")
@@ -298,19 +298,19 @@ func sockConn(timeout time.Duration) (net.Conn, error) {
}
}
func sockRequest(method, endpoint string, data interface{}) ([]byte, error) {
func sockRequest(method, endpoint string, data interface{}) (int, []byte, error) {
jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(data); err != nil {
return nil, err
return -1, nil, err
}
return sockRequestRaw(method, endpoint, jsonData, "application/json")
}
func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte, error) {
func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (int, []byte, error) {
c, err := sockConn(time.Duration(10 * time.Second))
if err != nil {
return nil, fmt.Errorf("could not dial docker daemon: %v", err)
return -1, nil, fmt.Errorf("could not dial docker daemon: %v", err)
}
client := httputil.NewClientConn(c, nil)
@@ -318,7 +318,7 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte,
req, err := http.NewRequest(method, endpoint, data)
if err != nil {
return nil, fmt.Errorf("could not create new request: %v", err)
return -1, nil, fmt.Errorf("could not create new request: %v", err)
}
if ct == "" {
@@ -328,15 +328,17 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) ([]byte,
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("could not perform request: %v", err)
return -1, nil, fmt.Errorf("could not perform request: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := ioutil.ReadAll(resp.Body)
return body, fmt.Errorf("received status != 200 OK: %s", resp.Status)
return resp.StatusCode, body, fmt.Errorf("received status != 200 OK: %s", resp.Status)
}
return ioutil.ReadAll(resp.Body)
b, err := ioutil.ReadAll(resp.Body)
return resp.StatusCode, b, err
}
func deleteContainer(container string) error {
@@ -1041,7 +1043,7 @@ func daemonTime(t *testing.T) time.Time {
return time.Now()
}
body, err := sockRequest("GET", "/info", nil)
_, body, err := sockRequest("GET", "/info", nil)
if err != nil {
t.Fatalf("daemonTime: failed to get /info: %v", err)
}
@@ -57,7 +57,7 @@ var (
func() bool {
if daemonExecDriver == "" {
// get daemon info
body, err := sockRequest("GET", "/info", nil)
_, body, err := sockRequest("GET", "/info", nil)
if err != nil {
log.Fatalf("sockRequest failed for /info: %v", err)
}