本文整理匯總了Golang中github.com/dotcloud/docker/engine.Env.GetList方法的典型用法代碼示例。如果您正苦於以下問題:Golang Env.GetList方法的具體用法?Golang Env.GetList怎麽用?Golang Env.GetList使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/dotcloud/docker/engine.Env
的用法示例。
在下文中一共展示了Env.GetList方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestGetContainersTop
func TestGetContainersTop(t *testing.T) {
eng := NewTestEngine(t)
defer mkRuntimeFromEngine(eng, t).Nuke()
srv := mkServerFromEngine(eng, t)
containerID := createTestContainer(eng,
&docker.Config{
Image: unitTestImageID,
Cmd: []string{"/bin/sh", "-c", "cat"},
OpenStdin: true,
},
t,
)
defer func() {
// Make sure the process dies before destroying runtime
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)
}
if err := docker.ServeRequest(srv, docker.APIVERSION, r, req); err != nil {
t.Fatal(err)
}
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])
}
}