mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
restart: add test for recording restart policy name
Add test for recording restart policy name on - restart=no - restart=always - restart=on-failure Signed-off-by: Hu Keping <hukeping@huawei.com>
This commit is contained in:
parent
2082ff82b5
commit
c3ed49dcdb
1 changed files with 69 additions and 0 deletions
|
@ -151,3 +151,72 @@ func TestRestartWithVolumes(t *testing.T) {
|
||||||
|
|
||||||
logDone("restart - does not create a new volume on restart")
|
logDone("restart - does not create a new volume on restart")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRecordRestartPolicyNO(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-d", "--restart=no", "busybox", "false")
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
id := strings.TrimSpace(string(out))
|
||||||
|
name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
if name != "no" {
|
||||||
|
t.Fatalf("Container restart policy name is %s, expected %s", name, "no")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("restart - recording restart policy name for --restart=no")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecordRestartPolicyAlways(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-d", "--restart=always", "busybox", "false")
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
id := strings.TrimSpace(string(out))
|
||||||
|
name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
if name != "always" {
|
||||||
|
t.Fatalf("Container restart policy name is %s, expected %s", name, "always")
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command(dockerBinary, "stop", id)
|
||||||
|
out, _, err = runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("restart - recording restart policy name for --restart=always")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRecordRestartPolicyOnFailure(t *testing.T) {
|
||||||
|
defer deleteAllContainers()
|
||||||
|
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "-d", "--restart=on-failure:1", "busybox", "false")
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
id := strings.TrimSpace(string(out))
|
||||||
|
name, err := inspectField(id, "HostConfig.RestartPolicy.Name")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err, out)
|
||||||
|
}
|
||||||
|
if name != "on-failure" {
|
||||||
|
t.Fatalf("Container restart policy name is %s, expected %s", name, "on-failure")
|
||||||
|
}
|
||||||
|
|
||||||
|
logDone("restart - recording restart policy name for --restart=on-failure")
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue