Move TestPostJsonVerify to integration-cli

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2015-04-14 21:55:04 -04:00
parent 23fa7d41d5
commit 5dc02a2fa8
3 changed files with 42 additions and 41 deletions

View File

@ -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")
}

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 {

View File

@ -22,44 +22,6 @@ import (
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
)
func TestPostJsonVerify(t *testing.T) {
eng := NewTestEngine(t)
defer mkDaemonFromEngine(eng, t).Nuke()
configJSON, err := json.Marshal(&runconfig.Config{
Image: unitTestImageID,
Cmd: runconfig.NewCommand("touch", "/test"),
})
if err != nil {
t.Fatal(err)
}
req, err := http.NewRequest("POST", "/containers/create", bytes.NewReader(configJSON))
if err != nil {
t.Fatal(err)
}
r := httptest.NewRecorder()
server.ServeRequest(eng, api.APIVERSION, r, req)
// Don't add Content-Type header
// req.Header.Set("Content-Type", "application/json")
server.ServeRequest(eng, api.APIVERSION, r, req)
if r.Code != http.StatusInternalServerError || !strings.Contains(((*r.Body).String()), "application/json") {
t.Fatal("Create should have failed due to no Content-Type header - got:", r)
}
// Now add header but with wrong type and retest
req.Header.Set("Content-Type", "application/xml")
server.ServeRequest(eng, api.APIVERSION, r, req)
if r.Code != http.StatusInternalServerError || !strings.Contains(((*r.Body).String()), "application/json") {
t.Fatal("Create should have failed due to wrong Content-Type header - got:", r)
}
}
// Issue 7941 - test to make sure a "null" in JSON is just ignored.
// W/o this fix a null in JSON would be parsed into a string var as "null"
func TestPostCreateNull(t *testing.T) {