Move TestGetContainersTop to integration-cli
Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
parent
6f5b895bc7
commit
d9e4b14346
2 changed files with 41 additions and 74 deletions
|
@ -624,3 +624,44 @@ func TestContainerApiPause(t *testing.T) {
|
|||
|
||||
logDone("container REST API - check POST containers/pause and unpause")
|
||||
}
|
||||
|
||||
func TestContainerApiTop(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
out, _, _ := dockerCmd(t, "run", "-d", "-i", "busybox", "/bin/sh", "-c", "cat")
|
||||
id := strings.TrimSpace(out)
|
||||
if err := waitRun(id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
type topResp struct {
|
||||
Titles []string
|
||||
Processes [][]string
|
||||
}
|
||||
var top topResp
|
||||
_, b, err := sockRequest("GET", "/containers/"+id+"/top?ps_args=aux", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := json.Unmarshal(b, &top); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(top.Titles) != 11 {
|
||||
t.Fatalf("expected 11 titles, found %d: %v", len(top.Titles), top.Titles)
|
||||
}
|
||||
|
||||
if top.Titles[0] != "USER" || top.Titles[10] != "COMMAND" {
|
||||
t.Fatalf("expected `USER` at `Titles[0]` and `COMMAND` at Titles[10]: %v", top.Titles)
|
||||
}
|
||||
if len(top.Processes) != 2 {
|
||||
t.Fatalf("expeted 2 processes, found %d: %v", len(top.Processes), top.Processes)
|
||||
}
|
||||
if top.Processes[0][10] != "/bin/sh -c cat" {
|
||||
t.Fatalf("expected `/bin/sh -c cat`, found: %s", top.Processes[0][10])
|
||||
}
|
||||
if top.Processes[1][10] != "cat" {
|
||||
t.Fatalf("expected `cat`, found: %s", top.Processes[1][10])
|
||||
}
|
||||
|
||||
logDone("containers REST API - GET /containers/<id>/top")
|
||||
}
|
||||
|
|
|
@ -23,80 +23,6 @@ import (
|
|||
"github.com/docker/docker/vendor/src/code.google.com/p/go/src/pkg/archive/tar"
|
||||
)
|
||||
|
||||
func TestGetContainersTop(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
defer mkDaemonFromEngine(eng, t).Nuke()
|
||||
|
||||
containerID := createTestContainer(eng,
|
||||
&runconfig.Config{
|
||||
Image: unitTestImageID,
|
||||
Cmd: runconfig.NewCommand("/bin/sh", "-c", "cat"),
|
||||
OpenStdin: true,
|
||||
},
|
||||
t,
|
||||
)
|
||||
defer func() {
|
||||
// Make sure the process dies before destroying daemon
|
||||
containerKill(eng, containerID, t)
|
||||
containerWait(eng, containerID, t)
|
||||
}()
|
||||
|
||||
startContainer(eng, containerID, t)
|
||||
|
||||
setTimeout(t, "Waiting for the container to be started timed out", 10*time.Second, func() {
|
||||
for {
|
||||
if containerRunning(eng, containerID, t) {
|
||||
break
|
||||
}
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
})
|
||||
|
||||
if !containerRunning(eng, containerID, t) {
|
||||
t.Fatalf("Container should be running")
|
||||
}
|
||||
|
||||
// Make sure sh spawn up cat
|
||||
setTimeout(t, "read/write assertion timed out", 2*time.Second, func() {
|
||||
in, out := containerAttach(eng, containerID, t)
|
||||
if err := assertPipe("hello\n", "hello", out, in, 150); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
r := httptest.NewRecorder()
|
||||
req, err := http.NewRequest("GET", "/containers/"+containerID+"/top?ps_args=aux", nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
server.ServeRequest(eng, api.APIVERSION, r, req)
|
||||
assertHttpNotError(r, t)
|
||||
var procs engine.Env
|
||||
if err := procs.Decode(r.Body); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if len(procs.GetList("Titles")) != 11 {
|
||||
t.Fatalf("Expected 11 titles, found %d.", len(procs.GetList("Titles")))
|
||||
}
|
||||
if procs.GetList("Titles")[0] != "USER" || procs.GetList("Titles")[10] != "COMMAND" {
|
||||
t.Fatalf("Expected Titles[0] to be USER and Titles[10] to be COMMAND, found %s and %s.", procs.GetList("Titles")[0], procs.GetList("Titles")[10])
|
||||
}
|
||||
processes := [][]string{}
|
||||
if err := procs.GetJson("Processes", &processes); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(processes) != 2 {
|
||||
t.Fatalf("Expected 2 processes, found %d.", len(processes))
|
||||
}
|
||||
if processes[0][10] != "/bin/sh -c cat" {
|
||||
t.Fatalf("Expected `/bin/sh -c cat`, found %s.", processes[0][10])
|
||||
}
|
||||
if processes[1][10] != "/bin/sh -c cat" {
|
||||
t.Fatalf("Expected `/bin/sh -c cat`, found %s.", processes[1][10])
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostCommit(t *testing.T) {
|
||||
eng := NewTestEngine(t)
|
||||
b := &builder.BuilderJob{Engine: eng}
|
||||
|
|
Loading…
Reference in a new issue