Move TestPostJsonVerify to integration-cli

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff
2015-04-16 13:49:28 -04:00
parent 23fa7d41d5
commit 5dc02a2fa8
3 changed files with 42 additions and 41 deletions
@@ -721,3 +721,43 @@ func TestContainerApiCreate(t *testing.T) {
logDone("containers REST API - POST /containers/create")
}
func TestContainerApiVerifyHeader(t *testing.T) {
defer deleteAllContainers()
config := map[string]interface{}{
"Image": "busybox",
}
create := func(ct string) (int, io.ReadCloser, error) {
jsonData := bytes.NewBuffer(nil)
if err := json.NewEncoder(jsonData).Encode(config); err != nil {
t.Fatal(err)
}
return sockRequestRaw("POST", "/containers/create", jsonData, ct)
}
// Try with no content-type
_, body, err := create("")
if err == nil {
b, _ := readBody(body)
t.Fatalf("expected error when content-type is not set: %q", string(b))
}
body.Close()
// Try with wrong content-type
_, body, err = create("application/xml")
if err == nil {
b, _ := readBody(body)
t.Fatalf("expected error when content-type is not set: %q", string(b))
}
body.Close()
// now application/json
_, body, err = create("application/json")
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
b, _ := readBody(body)
t.Fatalf("%v - %q", err, string(b))
}
body.Close()
logDone("containers REST API - verify create header")
}
+2 -3
View File
@@ -329,10 +329,9 @@ func sockRequestRaw(method, endpoint string, data io.Reader, ct string) (int, io
return -1, nil, fmt.Errorf("could not create new request: %v", err)
}
if ct == "" {
ct = "application/json"
if ct != "" {
req.Header.Set("Content-Type", ct)
}
req.Header.Set("Content-Type", ct)
resp, err := client.Do(req)
if err != nil {