Skip to content

Commit

Permalink
Tests on container state changing
Browse files Browse the repository at this point in the history
It could catch error that was fixed in moby#6954
Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <[email protected]> (github: LK4D4)
  • Loading branch information
LK4D4 committed Jul 18, 2014
1 parent 3660869 commit 4162309
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions integration-cli/docker_cli_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1295,3 +1295,69 @@ func TestAttachStdOutAndErrTTYMode(t *testing.T) {

logDone("run - Attach stderr and stdout with -t")
}

func TestState(t *testing.T) {
defer deleteAllContainers()
cmd := exec.Command(dockerBinary, "run", "-d", "busybox", "top")

out, _, err := runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
id := strings.TrimSpace(out)
state, err := inspectField(id, "State.Running")
if err != nil {
t.Fatal(err)
}
if state != "true" {
t.Fatal("Container state is 'not running'")
}
pid1, err := inspectField(id, "State.Pid")
if err != nil {
t.Fatal(err)
}
if pid1 == "0" {
t.Fatal("Container state Pid 0")
}

cmd = exec.Command(dockerBinary, "stop", id)
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
state, err = inspectField(id, "State.Running")
if err != nil {
t.Fatal(err)
}
if state != "false" {
t.Fatal("Container state is 'running'")
}
pid2, err := inspectField(id, "State.Pid")
if err != nil {
t.Fatal(err)
}
if pid2 == pid1 {
t.Fatalf("Container state Pid %s, but expected %s", pid2, pid1)
}

cmd = exec.Command(dockerBinary, "start", id)
out, _, err = runCommandWithOutput(cmd)
if err != nil {
t.Fatal(err, out)
}
state, err = inspectField(id, "State.Running")
if err != nil {
t.Fatal(err)
}
if state != "true" {
t.Fatal("Container state is 'not running'")
}
pid3, err := inspectField(id, "State.Pid")
if err != nil {
t.Fatal(err)
}
if pid3 == pid1 {
t.Fatalf("Container state Pid %s, but expected %s", pid2, pid1)
}
logDone("run - test container state.")
}

0 comments on commit 4162309

Please sign in to comment.