diff --git a/api.go b/api.go index 7b6825e804..ad308335cc 100644 --- a/api.go +++ b/api.go @@ -349,7 +349,7 @@ func postCommit(srv *Server, version float64, w http.ResponseWriter, r *http.Req return err } config := &Config{} - if err := json.NewDecoder(r.Body).Decode(config); err != nil { + if err := json.NewDecoder(r.Body).Decode(config); err != nil && err != io.EOF { utils.Errorf("%s", err) } repo := r.Form.Get("repo") diff --git a/api_test.go b/api_test.go index bcf662e9e7..fcb3bc8593 100644 --- a/api_test.go +++ b/api_test.go @@ -5,6 +5,7 @@ import ( "bufio" "bytes" "encoding/json" + "fmt" "github.com/dotcloud/docker/utils" "io" "net" @@ -12,6 +13,7 @@ import ( "net/http/httptest" "os" "path" + "strings" "testing" "time" ) @@ -40,6 +42,25 @@ func TestGetBoolParam(t *testing.T) { } } +func TesthttpError(t *testing.T) { + r := httptest.NewRecorder() + + httpError(r, fmt.Errorf("No such method")) + if r.Code != http.StatusNotFound { + t.Fatalf("Expected %d, got %d", http.StatusNotFound, r.Code) + } + + httpError(r, fmt.Errorf("This accound hasn't been activated")) + if r.Code != http.StatusForbidden { + t.Fatalf("Expected %d, got %d", http.StatusForbidden, r.Code) + } + + httpError(r, fmt.Errorf("Some error")) + if r.Code != http.StatusInternalServerError { + t.Fatalf("Expected %d, got %d", http.StatusInternalServerError, r.Code) + } +} + func TestGetVersion(t *testing.T) { var err error runtime := mkRuntime(t) @@ -243,7 +264,11 @@ func TestGetImagesJSON(t *testing.T) { t.Fatalf("Error expected, received none") } - httpError(r4, err) + if !strings.HasPrefix(err.Error(), "Bad parameter") { + t.Fatalf("Error should starts with \"Bad parameter\"") + } + http.Error(r4, err.Error(), http.StatusBadRequest) + if r4.Code != http.StatusBadRequest { t.Fatalf("%d Bad Request expected, received %d\n", http.StatusBadRequest, r4.Code) } @@ -776,6 +801,8 @@ func TestPostContainersStart(t *testing.T) { t.Fatal(err) } + req.Header.Set("Content-Type", "application/json") + r := httptest.NewRecorder() if err := postContainersStart(srv, APIVERSION, r, req, map[string]string{"name": container.ID}); err != nil { t.Fatal(err) diff --git a/buildfile.go b/buildfile.go index 64f04b3a3a..8231287eaf 100644 --- a/buildfile.go +++ b/buildfile.go @@ -176,7 +176,7 @@ func (b *buildFile) CmdEnv(args string) error { func (b *buildFile) CmdCmd(args string) error { var cmd []string if err := json.Unmarshal([]byte(args), &cmd); err != nil { - utils.Errorf("Error unmarshalling: %s, setting cmd to /bin/sh -c", err) + utils.Debugf("Error unmarshalling: %s, setting cmd to /bin/sh -c", err) cmd = []string{"/bin/sh", "-c", args} } if err := b.commit("", cmd, fmt.Sprintf("CMD %v", cmd)); err != nil {