use httpError in a separate test
This commit is contained in:
parent
27fc01271e
commit
df697b4318
1 changed files with 26 additions and 1 deletions
27
api_test.go
27
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue