Move TestPostCreateNull to integration-cli
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
5dc02a2fa8
commit
308a23021d
2 changed files with 56 additions and 61 deletions
|
@ -761,3 +761,59 @@ func TestContainerApiVerifyHeader(t *testing.T) {
|
|||
|
||||
logDone("containers REST API - verify create header")
|
||||
}
|
||||
|
||||
// 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 TestContainerApiPostCreateNull(t *testing.T) {
|
||||
config := `{
|
||||
"Hostname":"",
|
||||
"Domainname":"",
|
||||
"Memory":0,
|
||||
"MemorySwap":0,
|
||||
"CpuShares":0,
|
||||
"Cpuset":null,
|
||||
"AttachStdin":true,
|
||||
"AttachStdout":true,
|
||||
"AttachStderr":true,
|
||||
"PortSpecs":null,
|
||||
"ExposedPorts":{},
|
||||
"Tty":true,
|
||||
"OpenStdin":true,
|
||||
"StdinOnce":true,
|
||||
"Env":[],
|
||||
"Cmd":"ls",
|
||||
"Image":"busybox",
|
||||
"Volumes":{},
|
||||
"WorkingDir":"",
|
||||
"Entrypoint":null,
|
||||
"NetworkDisabled":false,
|
||||
"OnBuild":null}`
|
||||
|
||||
_, body, err := sockRequestRaw("POST", "/containers/create", strings.NewReader(config), "application/json")
|
||||
if err != nil && !strings.Contains(err.Error(), "200 OK: 201") {
|
||||
b, _ := readBody(body)
|
||||
t.Fatal(err, string(b))
|
||||
}
|
||||
|
||||
b, err := readBody(body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
type createResp struct {
|
||||
Id string
|
||||
}
|
||||
var container createResp
|
||||
if err := json.Unmarshal(b, &container); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
out, err := inspectField(container.Id, "HostConfig.CpusetCpus")
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
if out != "" {
|
||||
t.Fatalf("expected empty string, got %q", out)
|
||||
}
|
||||
|
||||
logDone("containers REST API - Create Null")
|
||||
}
|
||||
|
|
|
@ -4,13 +4,11 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -22,65 +20,6 @@ import (
|
|||
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||
)
|
||||
|
||||
// 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) {
|
||||
eng := NewTestEngine(t)
|
||||
daemon := mkDaemonFromEngine(eng, t)
|
||||
defer daemon.Nuke()
|
||||
|
||||
configStr := fmt.Sprintf(`{
|
||||
"Hostname":"",
|
||||
"Domainname":"",
|
||||
"Memory":0,
|
||||
"MemorySwap":0,
|
||||
"CpuShares":0,
|
||||
"Cpuset":null,
|
||||
"AttachStdin":true,
|
||||
"AttachStdout":true,
|
||||
"AttachStderr":true,
|
||||
"PortSpecs":null,
|
||||
"ExposedPorts":{},
|
||||
"Tty":true,
|
||||
"OpenStdin":true,
|
||||
"StdinOnce":true,
|
||||
"Env":[],
|
||||
"Cmd":"ls",
|
||||
"Image":"%s",
|
||||
"Volumes":{},
|
||||
"WorkingDir":"",
|
||||
"Entrypoint":null,
|
||||
"NetworkDisabled":false,
|
||||
"OnBuild":null}`, unitTestImageID)
|
||||
|
||||
req, err := http.NewRequest("POST", "/containers/create", strings.NewReader(configStr))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
r := httptest.NewRecorder()
|
||||
server.ServeRequest(eng, api.APIVERSION, r, req)
|
||||
assertHttpNotError(r, t)
|
||||
if r.Code != http.StatusCreated {
|
||||
t.Fatalf("%d Created expected, received %d\n", http.StatusCreated, r.Code)
|
||||
}
|
||||
|
||||
var apiRun engine.Env
|
||||
if err := apiRun.Decode(r.Body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
containerID := apiRun.Get("Id")
|
||||
|
||||
containerAssertExists(eng, containerID, t)
|
||||
|
||||
c, _ := daemon.Get(containerID)
|
||||
if c.HostConfig().CpusetCpus != "" {
|
||||
t.Fatalf("Cpuset should have been empty - instead its:" + c.HostConfig().CpusetCpus)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostContainersKill(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
defer mkDaemonFromEngine(eng, t).Nuke()
|
||||
|
|
Loading…
Reference in a new issue