From 648c4f198b7215a35f31deb9cdf4d370049ef4b2 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 28 Jun 2013 16:27:00 +0000 Subject: [PATCH] Add test --- api_test.go | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/api_test.go b/api_test.go index 4306f74100..f0ce4bf9f7 100644 --- a/api_test.go +++ b/api_test.go @@ -475,6 +475,61 @@ func TestGetContainersChanges(t *testing.T) { } } +func TestGetContainersProc(t *testing.T) { + runtime, err := newTestRuntime() + if err != nil { + t.Fatal(err) + } + defer nuke(runtime) + + srv := &Server{runtime: runtime} + + builder := NewBuilder(runtime) + + container, err := builder.Create( + &Config{ + Image: GetTestImage(runtime).ID, + Cmd: []string{"/bin/sh", "-c", "sleep 2"}, + }, + ) + if err != nil { + t.Fatal(err) + } + defer runtime.Destroy(container) + hostConfig := &HostConfig{} + if err := container.Start(hostConfig); err != nil { + t.Fatal(err) + } + + // Give some time to the process to start + container.WaitTimeout(500 * time.Millisecond) + + if !container.State.Running { + t.Errorf("Container should be running") + } + + r := httptest.NewRecorder() + if err := getContainersProc(srv, APIVERSION, r, nil, map[string]string{"name": container.ID}); err != nil { + t.Fatal(err) + } + procs := []APIProc{} + if err := json.Unmarshal(r.Body.Bytes(), &procs); err != nil { + t.Fatal(err) + } + + if len(procs) != 2 { + t.Fatalf("Expected 2 processes, found %d.", len(procs)) + } + + if procs[0].Cmd != "sh" && procs[0].Cmd != "exe" { + t.Fatalf("Expected `sleep` or `sh`, found %s.", procs[0].Cmd) + } + + if procs[1].Cmd != "sh" && procs[1].Cmd != "exe" { + t.Fatalf("Expected `sleep` or `sh`, found %s.", procs[1].Cmd) + } +} + func TestGetContainersByName(t *testing.T) { runtime, err := newTestRuntime() if err != nil {