mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add TestDaemonRestartWithRunningContainersPorts
Docker-DCO-1.1-Signed-off-by: Tibor Vass <teabee89@gmail.com> (github: tiborvass)
This commit is contained in:
parent
054b921a2c
commit
a9971a89cc
1 changed files with 50 additions and 0 deletions
50
integration-cli/docker_cli_daemon_test.go
Normal file
50
integration-cli/docker_cli_daemon_test.go
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDaemonRestartWithRunningContainersPorts(t *testing.T) {
|
||||||
|
d := NewDaemon(t)
|
||||||
|
if err := d.StartWithBusybox(); err != nil {
|
||||||
|
t.Fatalf("Could not start daemon with busybox: %v", err)
|
||||||
|
}
|
||||||
|
defer d.Stop()
|
||||||
|
|
||||||
|
if out, err := d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"); err != nil {
|
||||||
|
t.Fatalf("Could not run top1: err=%v\n%s", err, out)
|
||||||
|
}
|
||||||
|
// --restart=no by default
|
||||||
|
if out, err := d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"); err != nil {
|
||||||
|
t.Fatalf("Could not run top2: err=%v\n%s", err, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
testRun := func(m map[string]bool, prefix string) {
|
||||||
|
var format string
|
||||||
|
for c, shouldRun := range m {
|
||||||
|
out, err := d.Cmd("ps")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Could not run ps: err=%v\n%q", err, out)
|
||||||
|
}
|
||||||
|
if shouldRun {
|
||||||
|
format = "%scontainer %q is not running"
|
||||||
|
} else {
|
||||||
|
format = "%scontainer %q is running"
|
||||||
|
}
|
||||||
|
if shouldRun != strings.Contains(out, c) {
|
||||||
|
t.Fatalf(format, prefix, c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
testRun(map[string]bool{"top1": true, "top2": true}, "")
|
||||||
|
|
||||||
|
if err := d.Restart(); err != nil {
|
||||||
|
t.Fatalf("Could not restart daemon: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ")
|
||||||
|
|
||||||
|
logDone("daemon - running containers on daemon restart")
|
||||||
|
}
|
Loading…
Reference in a new issue