diff --git a/api_test.go b/api_test.go index bcf662e9e7..83ece7859c 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) }