Created
October 18, 2015 16:32
-
-
Save vdemeester/01ef68938b4a2a36b88a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| commit 93cd1936569f3d009b1208620e1deab39dc3c499 | |
| Author: Vincent Demeester <[email protected]> | |
| Date: Sat Oct 17 23:08:25 2015 +0200 | |
| Use checker assert for docker_cli_daemon_test.go | |
| Signed-off-by: Vincent Demeester <[email protected]> | |
| diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go | |
| index 6567809..856631f 100644 | |
| --- a/integration-cli/docker_cli_daemon_test.go | |
| +++ b/integration-cli/docker_cli_daemon_test.go | |
| @@ -16,101 +16,85 @@ import ( | |
| "strings" | |
| "time" | |
| + "github.com/docker/docker/pkg/integration/checker" | |
| "github.com/docker/libnetwork/iptables" | |
| "github.com/docker/libtrust" | |
| "github.com/go-check/check" | |
| ) | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithRunningContainersPorts(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| + | |
| + out, err := s.d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run top1: %s", out)) | |
| - if out, err := s.d.Cmd("run", "-d", "--name", "top1", "-p", "1234:80", "--restart", "always", "busybox:latest", "top"); err != nil { | |
| - c.Fatalf("Could not run top1: err=%v\n%s", err, out) | |
| - } | |
| // --restart=no by default | |
| - if out, err := s.d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top"); err != nil { | |
| - c.Fatalf("Could not run top2: err=%v\n%s", err, out) | |
| - } | |
| + out, err = s.d.Cmd("run", "-d", "--name", "top2", "-p", "80", "busybox:latest", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run top2: %s", out)) | |
| testRun := func(m map[string]bool, prefix string) { | |
| var format string | |
| for cont, shouldRun := range m { | |
| out, err := s.d.Cmd("ps") | |
| - if err != nil { | |
| - c.Fatalf("Could not run ps: err=%v\n%q", err, out) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run ps: %q", out)) | |
| if shouldRun { | |
| - format = "%scontainer %q is not running" | |
| + format = "%s container %q is not running" | |
| } else { | |
| - format = "%scontainer %q is running" | |
| - } | |
| - if shouldRun != strings.Contains(out, cont) { | |
| - c.Fatalf(format, prefix, cont) | |
| + format = "%s container %q is running" | |
| } | |
| + c.Assert(strings.Contains(out, cont), checker.Equals, shouldRun, check.Commentf(format, prefix, cont)) | |
| } | |
| } | |
| testRun(map[string]bool{"top1": true, "top2": true}, "") | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatalf("Could not restart daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil, check.Commentf("Could not restart daemon")) | |
| + | |
| testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ") | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithVolumesRefs(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| - if out, err := s.d.Cmd("run", "-d", "--name", "volrestarttest1", "-v", "/foo", "busybox"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| + out, err := s.d.Cmd("run", "-d", "--name", "volrestarttest1", "-v", "/foo", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| - if _, err := s.d.Cmd("run", "-d", "--volumes-from", "volrestarttest1", "--name", "volrestarttest2", "busybox", "top"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + out, err = s.d.Cmd("run", "-d", "--volumes-from", "volrestarttest1", "--name", "volrestarttest2", "busybox", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - if out, err := s.d.Cmd("rm", "-fv", "volrestarttest2"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| + out, err = s.d.Cmd("rm", "-fv", "volrestarttest2") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - out, err := s.d.Cmd("inspect", "-f", "{{json .Mounts}}", "volrestarttest1") | |
| - c.Assert(err, check.IsNil) | |
| + out, err = s.d.Cmd("inspect", "-f", "{{json .Mounts}}", "volrestarttest1") | |
| + c.Assert(err, checker.IsNil) | |
| - if _, err := inspectMountPointJSON(out, "/foo"); err != nil { | |
| - c.Fatalf("Expected volume to exist: /foo, error: %v\n", err) | |
| - } | |
| + _, err = inspectMountPointJSON(out, "/foo") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Expected volume to exist: /foo")) | |
| } | |
| // #11008 | |
| func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) { | |
| - err := s.d.StartWithBusybox() | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| out, err := s.d.Cmd("run", "-d", "--name", "top1", "--restart", "always", "busybox:latest", "top") | |
| - c.Assert(err, check.IsNil, check.Commentf("run top1: %v", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("run top1: %v", out)) | |
| out, err = s.d.Cmd("run", "-d", "--name", "top2", "--restart", "unless-stopped", "busybox:latest", "top") | |
| - c.Assert(err, check.IsNil, check.Commentf("run top2: %v", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("run top2: %v", out)) | |
| testRun := func(m map[string]bool, prefix string) { | |
| var format string | |
| for name, shouldRun := range m { | |
| out, err := s.d.Cmd("ps") | |
| - c.Assert(err, check.IsNil, check.Commentf("run ps: %v", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("run ps: %v", out)) | |
| if shouldRun { | |
| format = "%scontainer %q is not running" | |
| } else { | |
| format = "%scontainer %q is running" | |
| } | |
| - c.Assert(strings.Contains(out, name), check.Equals, shouldRun, check.Commentf(format, prefix, name)) | |
| + c.Assert(strings.Contains(out, name), checker.Equals, shouldRun, check.Commentf(format, prefix, name)) | |
| } | |
| } | |
| @@ -118,25 +102,25 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) { | |
| testRun(map[string]bool{"top1": true, "top2": true}, "") | |
| out, err = s.d.Cmd("stop", "top1") | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| out, err = s.d.Cmd("stop", "top2") | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| // both stopped | |
| testRun(map[string]bool{"top1": false, "top2": false}, "") | |
| err = s.d.Restart() | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| // restart=always running | |
| testRun(map[string]bool{"top1": true, "top2": false}, "After daemon restart: ") | |
| out, err = s.d.Cmd("start", "top2") | |
| - c.Assert(err, check.IsNil, check.Commentf("start top2: %v", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("start top2: %v", out)) | |
| err = s.d.Restart() | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| // both running | |
| testRun(map[string]bool{"top1": true, "top2": true}, "After second daemon restart: ") | |
| @@ -144,9 +128,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartUnlessStopped(c *check.C) { | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonStartIptablesFalse(c *check.C) { | |
| - if err := s.d.Start("--iptables=false"); err != nil { | |
| - c.Fatalf("we should have been able to start the daemon with passing iptables=false: %v", err) | |
| - } | |
| + c.Assert(s.d.Start("--iptables=false"), checker.IsNil, check.Commentf("we should have been able to start the daemon with passing iptables=false")) | |
| } | |
| // Issue #8444: If docker0 bridge is modified (intentionally or unintentionally) and | |
| @@ -156,107 +138,70 @@ func (s *DockerDaemonSuite) TestDaemonStartBridgeWithoutIPAssociation(c *check.C | |
| // rather than depending on brctl commands to verify docker0 is created and up | |
| // let's start the daemon and stop it, and then make a modification to run the | |
| // actual test | |
| - if err := s.d.Start(); err != nil { | |
| - c.Fatalf("Could not start daemon: %v", err) | |
| - } | |
| - if err := s.d.Stop(); err != nil { | |
| - c.Fatalf("Could not stop daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Could not start daemon")) | |
| + c.Assert(s.d.Stop(), checker.IsNil, check.Commentf("Could not stop daemon")) | |
| // now we will remove the ip from docker0 and then try starting the daemon | |
| ipCmd := exec.Command("ip", "addr", "flush", "dev", "docker0") | |
| stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd) | |
| - if err != nil { | |
| - c.Fatalf("failed to remove docker0 IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("failed to remove docker0 IP association: stdout: %q, stderr: %q", stdout, stderr)) | |
| - if err := s.d.Start(); err != nil { | |
| - warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix" | |
| - c.Fatalf("Could not start daemon when docker0 has no IP address: %v\n%s", err, warning) | |
| - } | |
| + warning := "**WARNING: Docker bridge network in bad state--delete docker0 bridge interface to fix" | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Could not start daemon when docker0 has no IP address: %s", warning)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonIptablesClean(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| - if out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top"); err != nil { | |
| - c.Fatalf("Could not run top: %s, %v", out, err) | |
| - } | |
| + out, err := s.d.Cmd("run", "-d", "--name", "top", "-p", "80", "busybox:latest", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run top: %s", out)) | |
| // get output from iptables with container running | |
| ipTablesSearchString := "tcp dpt:80" | |
| ipTablesCmd := exec.Command("iptables", "-nvL") | |
| - out, _, err := runCommandWithOutput(ipTablesCmd) | |
| - if err != nil { | |
| - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) | |
| - } | |
| + out, _, err = runCommandWithOutput(ipTablesCmd) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run iptables -nvL: %s", out)) | |
| - if !strings.Contains(out, ipTablesSearchString) { | |
| - c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out) | |
| - } | |
| + c.Assert(out, checker.Contains, ipTablesSearchString) | |
| - if err := s.d.Stop(); err != nil { | |
| - c.Fatalf("Could not stop daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Stop(), checker.IsNil, check.Commentf("could not stop daemon")) | |
| // get output from iptables after restart | |
| ipTablesCmd = exec.Command("iptables", "-nvL") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - if err != nil { | |
| - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run iptables -nvL: %s", out)) | |
| - if strings.Contains(out, ipTablesSearchString) { | |
| - c.Fatalf("iptables output should not have contained %q, but was %q", ipTablesSearchString, out) | |
| - } | |
| + c.Assert(out, checker.Not(checker.Contains), ipTablesSearchString) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| - if out, err := s.d.Cmd("run", "-d", "--name", "top", "--restart=always", "-p", "80", "busybox:latest", "top"); err != nil { | |
| - c.Fatalf("Could not run top: %s, %v", out, err) | |
| - } | |
| + out, err := s.d.Cmd("run", "-d", "--name", "top", "--restart=always", "-p", "80", "busybox:latest", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run top: %s", out)) | |
| // get output from iptables with container running | |
| ipTablesSearchString := "tcp dpt:80" | |
| ipTablesCmd := exec.Command("iptables", "-nvL") | |
| - out, _, err := runCommandWithOutput(ipTablesCmd) | |
| - if err != nil { | |
| - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) | |
| - } | |
| + out, _, err = runCommandWithOutput(ipTablesCmd) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run iptables -nvL: %s", out)) | |
| - if !strings.Contains(out, ipTablesSearchString) { | |
| - c.Fatalf("iptables output should have contained %q, but was %q", ipTablesSearchString, out) | |
| - } | |
| + c.Assert(out, checker.Contains, ipTablesSearchString) | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatalf("Could not restart daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| // make sure the container is not running | |
| runningOut, err := s.d.Cmd("inspect", "--format='{{.State.Running}}'", "top") | |
| - if err != nil { | |
| - c.Fatalf("Could not inspect on container: %s, %v", out, err) | |
| - } | |
| - if strings.TrimSpace(runningOut) != "true" { | |
| - c.Fatalf("Container should have been restarted after daemon restart. Status running should have been true but was: %q", strings.TrimSpace(runningOut)) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not inspect on container: %s", out)) | |
| + | |
| + c.Assert(strings.TrimSpace(runningOut), checker.Equals, "true", check.Commentf("Container should have been restarted after daemon restart. Status running should have been true.")) | |
| // get output from iptables after restart | |
| ipTablesCmd = exec.Command("iptables", "-nvL") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - if err != nil { | |
| - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run iptables -nvL: %s", out)) | |
| - if !strings.Contains(out, ipTablesSearchString) { | |
| - c.Fatalf("iptables output after restart should have contained %q, but was %q", ipTablesSearchString, out) | |
| - } | |
| + c.Assert(out, checker.Contains, ipTablesSearchString) | |
| } | |
| // TestDaemonIPv6Enabled checks that when the daemon is started with --ipv6=true that the docker0 bridge | |
| @@ -264,26 +209,18 @@ func (s *DockerDaemonSuite) TestDaemonIptablesCreate(c *check.C) { | |
| func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) { | |
| testRequires(c, IPv6) | |
| - if err := setupV6(); err != nil { | |
| - c.Fatal("Could not set up host for IPv6 tests") | |
| - } | |
| + setupV6(c) | |
| d := NewDaemon(c) | |
| - if err := d.StartWithBusybox("--ipv6"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(d.StartWithBusybox("--ipv6"), checker.IsNil) | |
| defer d.Stop() | |
| iface, err := net.InterfaceByName("docker0") | |
| - if err != nil { | |
| - c.Fatalf("Error getting docker0 interface: %v", err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error getting docker0 interface")) | |
| addrs, err := iface.Addrs() | |
| - if err != nil { | |
| - c.Fatalf("Error getting addresses for docker0 interface: %v", err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error getting addresses for docker0 interface")) | |
| var found bool | |
| expected := "fe80::1/64" | |
| @@ -294,39 +231,28 @@ func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) { | |
| } | |
| } | |
| - if !found { | |
| - c.Fatalf("Bridge does not have an IPv6 Address") | |
| - } | |
| + c.Assert(found, checker.True, check.Commentf("Bridge does not have an IPv6 Address")) | |
| - if out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil { | |
| - c.Fatalf("Could not run container: %s, %v", out, err) | |
| - } | |
| + out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run container: %s", out)) | |
| - out, err := d.Cmd("inspect", "--format", "'{{.NetworkSettings.LinkLocalIPv6Address}}'", "ipv6test") | |
| + out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.LinkLocalIPv6Address}}'", "ipv6test") | |
| out = strings.Trim(out, " \r\n'") | |
| - if err != nil { | |
| - c.Fatalf("Error inspecting container: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error inspecting container: %s", out)) | |
| - if ip := net.ParseIP(out); ip == nil { | |
| - c.Fatalf("Container should have a link-local IPv6 address") | |
| - } | |
| + ip := net.ParseIP(out) | |
| + c.Assert(ip, checker.NotNil, check.Commentf("Container should have a link-local IPv6 address")) | |
| out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.GlobalIPv6Address}}'", "ipv6test") | |
| out = strings.Trim(out, " \r\n'") | |
| - if err != nil { | |
| - c.Fatalf("Error inspecting container: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error inspecting container: %s", out)) | |
| - if ip := net.ParseIP(out); ip != nil { | |
| - c.Fatalf("Container should not have a global IPv6 address: %v", out) | |
| - } | |
| + ip = net.ParseIP(out) | |
| + c.Assert(ip, checker.IsNil, check.Commentf("Container should not have a global IPv6 address: %v", out)) | |
| - if err := teardownV6(); err != nil { | |
| - c.Fatal("Could not perform teardown for IPv6 tests") | |
| - } | |
| + teardownV6(c) | |
| } | |
| @@ -335,45 +261,33 @@ func (s *DockerSuite) TestDaemonIPv6Enabled(c *check.C) { | |
| func (s *DockerSuite) TestDaemonIPv6FixedCIDR(c *check.C) { | |
| testRequires(c, IPv6) | |
| - if err := setupV6(); err != nil { | |
| - c.Fatal("Could not set up host for IPv6 tests") | |
| - } | |
| + setupV6(c) | |
| d := NewDaemon(c) | |
| - if err := d.StartWithBusybox("--ipv6", "--fixed-cidr-v6='2001:db8:1::/64'"); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(d.StartWithBusybox("--ipv6", "--fixed-cidr-v6='2001:db8:1::/64'"), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| defer d.Stop() | |
| - if out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest"); err != nil { | |
| - c.Fatalf("Could not run container: %s, %v", out, err) | |
| - } | |
| + out, err := d.Cmd("run", "-itd", "--name=ipv6test", "busybox:latest") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run container: %s", out)) | |
| - out, err := d.Cmd("inspect", "--format", "'{{.NetworkSettings.LinkLocalIPv6Address}}'", "ipv6test") | |
| - out = strings.Trim(out, " \r\n'") | |
| + out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.LinkLocalIPv6Address}}'", "ipv6test") | |
| - if err != nil { | |
| - c.Fatalf("Error inspecting container: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error inspecting container: %s", out)) | |
| - if ip := net.ParseIP(out); ip == nil { | |
| - c.Fatalf("Container should have a link-local IPv6 address") | |
| - } | |
| + out = strings.Trim(out, " \r\n'") | |
| + ip := net.ParseIP(out) | |
| + c.Assert(ip, checker.NotNil, check.Commentf("Container should have a link-local IPv6 address")) | |
| out, err = d.Cmd("inspect", "--format", "'{{.NetworkSettings.GlobalIPv6Address}}'", "ipv6test") | |
| out = strings.Trim(out, " \r\n'") | |
| - if err != nil { | |
| - c.Fatalf("Error inspecting container: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error inspecting container: %s", out)) | |
| - if ip := net.ParseIP(out); ip == nil { | |
| - c.Fatalf("Container should have a global IPv6 address") | |
| - } | |
| - if err := teardownV6(); err != nil { | |
| - c.Fatal("Could not perform teardown for IPv6 tests") | |
| - } | |
| + ip = net.ParseIP(out) | |
| + c.Assert(ip, checker.NotNil, check.Commentf("Container should have a global IPv6 address")) | |
| + | |
| + teardownV6(c) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLogLevelWrong(c *check.C) { | |
| @@ -396,10 +310,8 @@ func (s *DockerSuite) TestDaemonStartWithBackwardCompatibility(c *check.C) { | |
| for _, args := range validCommandArgs { | |
| d := NewDaemon(c) | |
| d.Command = "--daemon" | |
| - if err := d.Start(args...); err != nil { | |
| - c.Fatalf("Daemon should have started successfully with --daemon %v: %v", args, err) | |
| - } | |
| - d.Stop() | |
| + c.Assert(d.Start(args...), checker.IsNil, check.Commentf("Daemon should have started successfully with --daemon %v", args)) | |
| + c.Assert(d.Stop(), checker.IsNil, check.Commentf("Daemon should have stopped successfully with --daemon %v", args)) | |
| } | |
| for _, args := range invalidCommandArgs { | |
| @@ -439,10 +351,8 @@ func (s *DockerSuite) TestDaemonStartWithDaemonCommand(c *check.C) { | |
| for _, f := range flags { | |
| d := NewDaemon(c) | |
| args := append(f[common], f[daemon]...) | |
| - if err := d.Start(args...); err != nil { | |
| - c.Fatalf("Daemon should have started successfully with %v: %v", args, err) | |
| - } | |
| - d.Stop() | |
| + c.Assert(d.Start(args...), checker.IsNil, check.Commentf("Daemon should have started successfully with %v", args)) | |
| + c.Assert(d.Stop(), checker.IsNil, check.Commentf("Daemon should have stopped successfully with %v", args)) | |
| } | |
| // `docker -l info daemon --selinux-enabled` | |
| @@ -468,61 +378,44 @@ func (s *DockerSuite) TestDaemonStartWithDaemonCommand(c *check.C) { | |
| cmd.Process.Kill() | |
| case err = <-errch: | |
| } | |
| - if err == nil { | |
| - c.Fatalf("Daemon should have failed to start with docker %v daemon", f) | |
| - } | |
| + c.Assert(err, checker.NotNil, check.Commentf("Daemon should have failed to start with docker %v daemon", f)) | |
| } | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLogLevelDebug(c *check.C) { | |
| - if err := s.d.Start("--log-level=debug"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("--log-level=debug"), checker.IsNil) | |
| + | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), `level=debug`) { | |
| - c.Fatalf(`Missing level="debug" in log file:\n%s`, string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Contains, `level=debug`) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLogLevelFatal(c *check.C) { | |
| // we creating new daemons to create new logFile | |
| - if err := s.d.Start("--log-level=fatal"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("--log-level=fatal"), checker.IsNil) | |
| + | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if strings.Contains(string(content), `level=debug`) { | |
| - c.Fatalf(`Should not have level="debug" in log file:\n%s`, string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Not(checker.Contains), `level=debug`, check.Commentf(`Should not have level="debug" in log file`)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonFlagD(c *check.C) { | |
| - if err := s.d.Start("-D"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("-D"), checker.IsNil) | |
| + | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), `level=debug`) { | |
| - c.Fatalf(`Should have level="debug" in log file using -D:\n%s`, string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Contains, `level=debug`, check.Commentf(`Should have level="debug" in log file using -D`)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonFlagDebug(c *check.C) { | |
| - if err := s.d.Start("--debug"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("--debug"), checker.IsNil) | |
| + | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), `level=debug`) { | |
| - c.Fatalf(`Should have level="debug" in log file using --debug:\n%s`, string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Contains, `level=debug`, check.Commentf(`Should have level="debug" in log file using --debug`)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonFlagDebugLogLevelFatal(c *check.C) { | |
| - if err := s.d.Start("--debug", "--log-level=fatal"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("--debug", "--log-level=fatal"), checker.IsNil) | |
| + | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), `level=debug`) { | |
| - c.Fatalf(`Should have level="debug" in log file when using both --debug and --log-level=fatal:\n%s`, string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Contains, `level=debug`, check.Commentf(`Should have level="debug" in log file when using both --debug and --log-level=fatal`)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *check.C) { | |
| @@ -537,65 +430,48 @@ func (s *DockerDaemonSuite) TestDaemonAllocatesListeningPort(c *check.C) { | |
| cmdArgs = append(cmdArgs, "--host", fmt.Sprintf("tcp://%s:%s", hostDirective[0], hostDirective[2])) | |
| } | |
| - if err := s.d.StartWithBusybox(cmdArgs...); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(cmdArgs...), check.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| for _, hostDirective := range listeningPorts { | |
| output, err := s.d.Cmd("run", "-p", fmt.Sprintf("%s:%s:80", hostDirective[1], hostDirective[2]), "busybox", "true") | |
| - if err == nil { | |
| - c.Fatalf("Container should not start, expected port already allocated error: %q", output) | |
| - } else if !strings.Contains(output, "port is already allocated") { | |
| - c.Fatalf("Expected port is already allocated error: %q", output) | |
| - } | |
| + c.Assert(err, checker.NotNil, check.Commentf("Container should not start, expected port already allocated error: %q", output)) | |
| + c.Assert(output, checker.Contains, "port is already allocated") | |
| } | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonKeyGeneration(c *check.C) { | |
| // TODO: skip or update for Windows daemon | |
| os.Remove("/etc/docker/key.json") | |
| - if err := s.d.Start(); err != nil { | |
| - c.Fatalf("Could not start daemon: %v", err) | |
| - } | |
| - s.d.Stop() | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Could not start daemon")) | |
| + c.Assert(s.d.Stop(), checker.IsNil) | |
| k, err := libtrust.LoadKeyFile("/etc/docker/key.json") | |
| - if err != nil { | |
| - c.Fatalf("Error opening key file") | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error opening key file")) | |
| + | |
| kid := k.KeyID() | |
| // Test Key ID is a valid fingerprint (e.g. QQXN:JY5W:TBXI:MK3X:GX6P:PD5D:F56N:NHCS:LVRZ:JA46:R24J:XEFF) | |
| - if len(kid) != 59 { | |
| - c.Fatalf("Bad key ID: %s", kid) | |
| - } | |
| + c.Assert(kid, checker.HasLen, 59, check.Commentf("Bad key ID: %s", kid)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonKeyMigration(c *check.C) { | |
| // TODO: skip or update for Windows daemon | |
| os.Remove("/etc/docker/key.json") | |
| k1, err := libtrust.GenerateECP256PrivateKey() | |
| - if err != nil { | |
| - c.Fatalf("Error generating private key: %s", err) | |
| - } | |
| - if err := os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".docker"), 0755); err != nil { | |
| - c.Fatalf("Error creating .docker directory: %s", err) | |
| - } | |
| - if err := libtrust.SaveKey(filepath.Join(os.Getenv("HOME"), ".docker", "key.json"), k1); err != nil { | |
| - c.Fatalf("Error saving private key: %s", err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error generating private key")) | |
| - if err := s.d.Start(); err != nil { | |
| - c.Fatalf("Could not start daemon: %v", err) | |
| - } | |
| - s.d.Stop() | |
| + err = os.MkdirAll(filepath.Join(os.Getenv("HOME"), ".docker"), 0755) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error creating .docker directory")) | |
| + | |
| + err = libtrust.SaveKey(filepath.Join(os.Getenv("HOME"), ".docker", "key.json"), k1) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error saving private key")) | |
| + | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Could not start daemon")) | |
| + c.Assert(s.d.Stop(), checker.IsNil, check.Commentf("Could not stop daemon")) | |
| k2, err := libtrust.LoadKeyFile("/etc/docker/key.json") | |
| - if err != nil { | |
| - c.Fatalf("Error opening key file") | |
| - } | |
| - if k1.KeyID() != k2.KeyID() { | |
| - c.Fatalf("Key not migrated") | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error opening key file")) | |
| + | |
| + c.Assert(k1.KeyID(), checker.Equals, k2.KeyID(), check.Commentf("Key not migrated")) | |
| } | |
| // GH#11320 - verify that the daemon exits on failure properly | |
| @@ -605,14 +481,11 @@ func (s *DockerDaemonSuite) TestDaemonExitOnFailure(c *check.C) { | |
| //attempt to start daemon with incorrect flags (we know -b and --bip conflict) | |
| if err := s.d.Start("--bridge", "nosuchbridge", "--bip", "1.1.1.1"); err != nil { | |
| //verify we got the right error | |
| - if !strings.Contains(err.Error(), "Daemon exited and never started") { | |
| - c.Fatalf("Expected daemon not to start, got %v", err) | |
| - } | |
| + c.Assert(err.Error(), checker.Contains, "Daemon exited and never started") | |
| // look in the log and make sure we got the message that daemon is shutting down | |
| runCmd := exec.Command("grep", "Error starting daemon", s.d.LogfileName()) | |
| - if out, _, err := runCommandWithOutput(runCmd); err != nil { | |
| - c.Fatalf("Expected 'Error starting daemon' message; but doesn't exist in log: %q, err: %v", out, err) | |
| - } | |
| + out, _, err := runCommandWithOutput(runCmd) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Expected 'Error starting daemon' message; but doesn't exist in log: %q", out)) | |
| } else { | |
| //if we didn't get an error and the daemon is running, this is a failure | |
| c.Fatal("Conflicting options should cause the daemon to error out with a failure") | |
| @@ -630,27 +503,25 @@ func (s *DockerDaemonSuite) TestDaemonBridgeExternal(c *check.C) { | |
| _, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) | |
| out, err := createInterface(c, "bridge", bridgeName, bridgeIP) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, bridgeName) | |
| err = d.StartWithBusybox("--bridge", bridgeName) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| ipTablesSearchString := bridgeIPNet.String() | |
| ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| - c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true, | |
| - check.Commentf("iptables output should have contained %q, but was %q", | |
| - ipTablesSearchString, out)) | |
| + c.Assert(out, checker.Contains, ipTablesSearchString) | |
| _, err = d.Cmd("run", "-d", "--name", "ExtContainer", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| containerIP := d.findContainerIP("ExtContainer") | |
| ip := net.ParseIP(containerIP) | |
| - c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, | |
| + c.Assert(bridgeIPNet.Contains(ip), checker.True, | |
| check.Commentf("Container IP-Address must be in the same subnet range : %s", | |
| containerIP)) | |
| } | |
| @@ -671,15 +542,15 @@ func createInterface(c *check.C, ifType string, ifName string, ipNet string) (st | |
| func deleteInterface(c *check.C, ifName string) { | |
| ifCmd := exec.Command("ip", "link", "delete", ifName) | |
| out, _, err := runCommandWithOutput(ifCmd) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| flushCmd := exec.Command("iptables", "-t", "nat", "--flush") | |
| out, _, err = runCommandWithOutput(flushCmd) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| flushCmd = exec.Command("iptables", "--flush") | |
| out, _, err = runCommandWithOutput(flushCmd) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) { | |
| @@ -701,46 +572,38 @@ func (s *DockerDaemonSuite) TestDaemonBridgeIP(c *check.C) { | |
| ip, bridgeIPNet, _ := net.ParseCIDR(bridgeIP) | |
| err := d.StartWithBusybox("--bip", bridgeIP) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| ifconfigSearchString := ip.String() | |
| ifconfigCmd := exec.Command("ifconfig", defaultNetworkBridge) | |
| out, _, _, err := runCommandWithStdoutStderr(ifconfigCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| - c.Assert(strings.Contains(out, ifconfigSearchString), check.Equals, true, | |
| - check.Commentf("ifconfig output should have contained %q, but was %q", | |
| - ifconfigSearchString, out)) | |
| + c.Assert(out, checker.Contains, ifconfigSearchString) | |
| ipTablesSearchString := bridgeIPNet.String() | |
| ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| - c.Assert(strings.Contains(out, ipTablesSearchString), check.Equals, true, | |
| - check.Commentf("iptables output should have contained %q, but was %q", | |
| - ipTablesSearchString, out)) | |
| + c.Assert(out, checker.Contains, ipTablesSearchString) | |
| out, err = d.Cmd("run", "-d", "--name", "test", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| containerIP := d.findContainerIP("test") | |
| ip = net.ParseIP(containerIP) | |
| - c.Assert(bridgeIPNet.Contains(ip), check.Equals, true, | |
| + c.Assert(bridgeIPNet.Contains(ip), checker.True, | |
| check.Commentf("Container IP-Address must be in the same subnet range : %s", | |
| containerIP)) | |
| deleteInterface(c, defaultNetworkBridge) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) { | |
| - if err := s.d.Start(); err != nil { | |
| - c.Fatalf("Could not start daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Could not start daemon")) | |
| defer s.d.Restart() | |
| - if err := s.d.Stop(); err != nil { | |
| - c.Fatalf("Could not stop daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Stop(), checker.IsNil, check.Commentf("Could not stop daemon")) | |
| // now we will change the docker0's IP and then try starting the daemon | |
| bridgeIP := "192.169.100.1/24" | |
| @@ -748,24 +611,16 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithBridgeIPChange(c *check.C) { | |
| ipCmd := exec.Command("ifconfig", "docker0", bridgeIP) | |
| stdout, stderr, _, err := runCommandWithStdoutStderr(ipCmd) | |
| - if err != nil { | |
| - c.Fatalf("failed to change docker0's IP association: %v, stdout: %q, stderr: %q", err, stdout, stderr) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("failed to change docker0's IP association: stdout: %q, stderr: %q", stdout, stderr)) | |
| - if err := s.d.Start("--bip", bridgeIP); err != nil { | |
| - c.Fatalf("Could not start daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Start("--bip", bridgeIP), checker.IsNil, check.Commentf("Could not start daemon")) | |
| //check if the iptables contains new bridgeIP MASQUERADE rule | |
| ipTablesSearchString := bridgeIPNet.String() | |
| ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") | |
| out, _, err := runCommandWithOutput(ipTablesCmd) | |
| - if err != nil { | |
| - c.Fatalf("Could not run iptables -nvL: %s, %v", out, err) | |
| - } | |
| - if !strings.Contains(out, ipTablesSearchString) { | |
| - c.Fatalf("iptables output should have contained new MASQUERADE rule with IP %q, but was %q", ipTablesSearchString, out) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run iptables -nvL: %s", out)) | |
| + c.Assert(out, checker.Contains, ipTablesSearchString, check.Commentf("iptables output should have contained new MASQUERADE rule")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) { | |
| @@ -775,20 +630,20 @@ func (s *DockerDaemonSuite) TestDaemonBridgeFixedCidr(c *check.C) { | |
| bridgeIP := "192.169.1.1/24" | |
| out, err := createInterface(c, "bridge", bridgeName, bridgeIP) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, bridgeName) | |
| args := []string{"--bridge", bridgeName, "--fixed-cidr", "192.169.1.0/30"} | |
| err = d.StartWithBusybox(args...) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| for i := 0; i < 4; i++ { | |
| cName := "Container" + strconv.Itoa(i) | |
| out, err := d.Cmd("run", "-d", "--name", cName, "busybox", "top") | |
| + // If there is an error, we only allow "no available IPV4 addresses" | |
| if err != nil { | |
| - c.Assert(strings.Contains(out, "no available IPv4 addresses"), check.Equals, true, | |
| - check.Commentf("Could not run a Container : %s %s", err.Error(), out)) | |
| + c.Assert(out, checker.Contains, "no available IPv4 addresses", check.Commentf("could not run a Container : %s", err.Error())) | |
| } | |
| } | |
| } | |
| @@ -803,14 +658,13 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Implicit(c *check.C) { | |
| bridgeIPNet := fmt.Sprintf("%s/24", bridgeIP) | |
| err := d.StartWithBusybox("--bip", bridgeIPNet) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| expectedMessage := fmt.Sprintf("default via %s dev", bridgeIP) | |
| out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0") | |
| - c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, | |
| - check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", | |
| - bridgeIP, strings.TrimSpace(out))) | |
| + c.Assert(out, checker.Contains, expectedMessage, check.Commentf("Implicit default gateway should be bridge IP %s, but default route was '%s'", | |
| + bridgeIP, strings.TrimSpace(out))) | |
| deleteInterface(c, defaultNetworkBridge) | |
| } | |
| @@ -825,14 +679,13 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4Explicit(c *check.C) { | |
| gatewayIP := "192.169.1.254" | |
| err := d.StartWithBusybox("--bip", bridgeIPNet, "--default-gateway", gatewayIP) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| expectedMessage := fmt.Sprintf("default via %s dev", gatewayIP) | |
| out, err := d.Cmd("run", "busybox", "ip", "-4", "route", "list", "0/0") | |
| - c.Assert(strings.Contains(out, expectedMessage), check.Equals, true, | |
| - check.Commentf("Explicit default gateway should be %s, but default route was '%s'", | |
| - gatewayIP, strings.TrimSpace(out))) | |
| + c.Assert(out, checker.Contains, expectedMessage, check.Commentf("Explicit default gateway should be %s, but default route was '%s'", | |
| + gatewayIP, strings.TrimSpace(out))) | |
| deleteInterface(c, defaultNetworkBridge) | |
| } | |
| @@ -842,7 +695,7 @@ func (s *DockerDaemonSuite) TestDaemonDefaultGatewayIPv4ExplicitOutsideContainer | |
| // Program a custom default gateway outside of the container subnet, daemon should accept it and start | |
| err := s.d.StartWithBusybox("--bip", "172.16.0.10/16", "--fixed-cidr", "172.16.1.0/24", "--default-gateway", "172.16.0.254") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| deleteInterface(c, defaultNetworkBridge) | |
| s.d.Restart() | |
| @@ -855,29 +708,29 @@ func (s *DockerDaemonSuite) TestDaemonIP(c *check.C) { | |
| ip, _, _ := net.ParseCIDR(ipStr) | |
| args := []string{"--ip", ip.String()} | |
| err := d.StartWithBusybox(args...) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| out, err := d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top") | |
| c.Assert(err, check.NotNil, | |
| check.Commentf("Running a container must fail with an invalid --ip option")) | |
| - c.Assert(strings.Contains(out, "Error starting userland proxy"), check.Equals, true) | |
| + c.Assert(out, checker.Contains, "Error starting userland proxy") | |
| ifName := "dummy" | |
| out, err = createInterface(c, "dummy", ifName, ipStr) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, ifName) | |
| _, err = d.Cmd("run", "-d", "-p", "8000:8000", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| ipTablesCmd := exec.Command("iptables", "-t", "nat", "-nvL") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| regex := fmt.Sprintf("DNAT.*%s.*dpt:8000", ip.String()) | |
| matched, _ := regexp.MatchString(regex, out) | |
| - c.Assert(matched, check.Equals, true, | |
| + c.Assert(matched, checker.True, | |
| check.Commentf("iptables output should have contained %q, but was %q", regex, out)) | |
| } | |
| @@ -888,21 +741,21 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) { | |
| bridgeIP := "192.169.1.1/24" | |
| out, err := createInterface(c, "bridge", bridgeName, bridgeIP) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, bridgeName) | |
| args := []string{"--bridge", bridgeName, "--icc=false"} | |
| err = d.StartWithBusybox(args...) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) | |
| matched, _ := regexp.MatchString(regex, out) | |
| - c.Assert(matched, check.Equals, true, | |
| + c.Assert(matched, checker.True, | |
| check.Commentf("iptables output should have contained %q, but was %q", regex, out)) | |
| // Pinging another container must fail with --icc=false | |
| @@ -918,7 +771,7 @@ func (s *DockerDaemonSuite) TestDaemonICCPing(c *check.C) { | |
| pingCmd := fmt.Sprintf("ping -c 1 %s -W 1", ip.String()) | |
| runArgs := []string{"--rm", "busybox", "sh", "-c", pingCmd} | |
| _, err = d.Cmd("run", runArgs...) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) { | |
| @@ -928,28 +781,28 @@ func (s *DockerDaemonSuite) TestDaemonICCLinkExpose(c *check.C) { | |
| bridgeIP := "192.169.1.1/24" | |
| out, err := createInterface(c, "bridge", bridgeName, bridgeIP) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, bridgeName) | |
| args := []string{"--bridge", bridgeName, "--icc=false"} | |
| err = d.StartWithBusybox(args...) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer d.Restart() | |
| ipTablesCmd := exec.Command("iptables", "-nvL", "FORWARD") | |
| out, _, err = runCommandWithOutput(ipTablesCmd) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| regex := fmt.Sprintf("DROP.*all.*%s.*%s", bridgeName, bridgeName) | |
| matched, _ := regexp.MatchString(regex, out) | |
| - c.Assert(matched, check.Equals, true, | |
| + c.Assert(matched, checker.True, | |
| check.Commentf("iptables output should have contained %q, but was %q", regex, out)) | |
| out, err = d.Cmd("run", "-d", "--expose", "4567", "--name", "icc1", "busybox", "nc", "-l", "-p", "4567") | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| out, err = d.Cmd("run", "--link", "icc1:icc1", "busybox", "nc", "icc1", "4567") | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *check.C) { | |
| @@ -957,31 +810,30 @@ func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *che | |
| bridgeIP := "192.169.1.1/24" | |
| out, err := createInterface(c, "bridge", bridgeName, bridgeIP) | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| defer deleteInterface(c, bridgeName) | |
| err = s.d.StartWithBusybox("--bridge", bridgeName, "--icc=false") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| defer s.d.Restart() | |
| _, err = s.d.Cmd("run", "-d", "--name", "child", "--publish", "8080:80", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| _, err = s.d.Cmd("run", "-d", "--name", "parent", "--link", "child:http", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| childIP := s.d.findContainerIP("child") | |
| parentIP := s.d.findContainerIP("parent") | |
| sourceRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", childIP, "--sport", "80", "-d", parentIP, "-j", "ACCEPT"} | |
| destinationRule := []string{"-i", bridgeName, "-o", bridgeName, "-p", "tcp", "-s", parentIP, "--dport", "80", "-d", childIP, "-j", "ACCEPT"} | |
| - if !iptables.Exists("filter", "DOCKER", sourceRule...) || !iptables.Exists("filter", "DOCKER", destinationRule...) { | |
| - c.Fatal("Iptables rules not found") | |
| - } | |
| + | |
| + c.Assert(iptables.Exists("filter", "DOCKER", sourceRule...), checker.True, check.Commentf("Iptables rules not found")) | |
| + c.Assert(iptables.Exists("filter", "DOCKER", destinationRule...), checker.True, check.Commentf("Iptables rules not found")) | |
| s.d.Cmd("rm", "--link", "parent/http") | |
| - if iptables.Exists("filter", "DOCKER", sourceRule...) || iptables.Exists("filter", "DOCKER", destinationRule...) { | |
| - c.Fatal("Iptables rules should be removed when unlink") | |
| - } | |
| + c.Assert(iptables.Exists("filter", "DOCKER", sourceRule...), checker.False, check.Commentf("Iptables rules should be removed when unlink")) | |
| + c.Assert(iptables.Exists("filter", "DOCKER", destinationRule...), checker.False, check.Commentf("Iptables rules should be removed when unlink")) | |
| s.d.Cmd("kill", "child") | |
| s.d.Cmd("kill", "parent") | |
| @@ -990,288 +842,210 @@ func (s *DockerDaemonSuite) TestDaemonLinksIpTablesRulesWhenLinkAndUnlink(c *che | |
| func (s *DockerDaemonSuite) TestDaemonUlimitDefaults(c *check.C) { | |
| testRequires(c, NativeExecDriver) | |
| - if err := s.d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox("--default-ulimit", "nofile=42:42", "--default-ulimit", "nproc=1024:1024"), checker.IsNil) | |
| out, err := s.d.Cmd("run", "--ulimit", "nproc=2048", "--name=test", "busybox", "/bin/sh", "-c", "echo $(ulimit -n); echo $(ulimit -p)") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| outArr := strings.Split(out, "\n") | |
| - if len(outArr) < 2 { | |
| - c.Fatalf("got unexpected output: %s", out) | |
| - } | |
| + c.Assert(len(outArr), checker.GreaterOrEqualThan, 2, check.Commentf("got unexpected output: %s", out)) | |
| + | |
| nofile := strings.TrimSpace(outArr[0]) | |
| nproc := strings.TrimSpace(outArr[1]) | |
| - if nofile != "42" { | |
| - c.Fatalf("expected `ulimit -n` to be `42`, got: %s", nofile) | |
| - } | |
| - if nproc != "2048" { | |
| - c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc) | |
| - } | |
| + c.Assert(nofile, checker.Equals, "42", check.Commentf("expected `ulimit -n` to be `42`")) | |
| + c.Assert(nproc, checker.Equals, "2048", check.Commentf("exepcted `ulimit -p` to be 2048")) | |
| // Now restart daemon with a new default | |
| - if err := s.d.Restart("--default-ulimit", "nofile=43"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Restart("--default-ulimit", "nofile=43"), checker.IsNil) | |
| out, err = s.d.Cmd("start", "-a", "test") | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| outArr = strings.Split(out, "\n") | |
| - if len(outArr) < 2 { | |
| - c.Fatalf("got unexpected output: %s", out) | |
| - } | |
| + c.Assert(len(outArr), checker.GreaterOrEqualThan, 2, check.Commentf("got unexpected output: %s", out)) | |
| + | |
| nofile = strings.TrimSpace(outArr[0]) | |
| nproc = strings.TrimSpace(outArr[1]) | |
| - if nofile != "43" { | |
| - c.Fatalf("expected `ulimit -n` to be `43`, got: %s", nofile) | |
| - } | |
| - if nproc != "2048" { | |
| - c.Fatalf("exepcted `ulimit -p` to be 2048, got: %s", nproc) | |
| - } | |
| + c.Assert(nofile, checker.Equals, "43", check.Commentf("expected `ulimit -n` to be `43`")) | |
| + c.Assert(nproc, checker.Equals, "2048", check.Commentf("exepcted `ulimit -p` to be 2048")) | |
| } | |
| // #11315 | |
| func (s *DockerDaemonSuite) TestDaemonRestartRenameContainer(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| - if out, err := s.d.Cmd("run", "--name=test", "busybox"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| + out, err := s.d.Cmd("run", "--name=test", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - if out, err := s.d.Cmd("rename", "test", "test2"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| + out, err = s.d.Cmd("rename", "test", "test2") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| - if out, err := s.d.Cmd("start", "test2"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| + out, err = s.d.Cmd("start", "test2") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefault(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| id := strings.TrimSpace(out) | |
| - if out, err := s.d.Cmd("wait", id); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("wait", id) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") | |
| - if _, err := os.Stat(logPath); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + _, err = os.Stat(logPath) | |
| + c.Assert(err, checker.IsNil) | |
| + | |
| f, err := os.Open(logPath) | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil) | |
| + | |
| var res struct { | |
| Log string `json:"log"` | |
| Stream string `json:"stream"` | |
| Time time.Time `json:"time"` | |
| } | |
| - if err := json.NewDecoder(f).Decode(&res); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| - if res.Log != "testline\n" { | |
| - c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n") | |
| - } | |
| - if res.Stream != "stdout" { | |
| - c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout") | |
| - } | |
| - if !time.Now().After(res.Time) { | |
| - c.Fatalf("Log time %v in future", res.Time) | |
| - } | |
| + c.Assert(json.NewDecoder(f).Decode(&res), checker.IsNil, check.Commentf("Fail to decode %v", f)) | |
| + | |
| + c.Assert(res.Log, checker.Equals, "testline\n", check.Commentf("Unexpected log line")) | |
| + c.Assert(res.Stream, checker.Contains, "stdout", check.Commentf("Unexpected stream")) | |
| + | |
| + c.Assert(time.Now(), checker.IsAfter, res.Time, check.Commentf("Log time in future")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLoggingDriverDefaultOverride(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| out, err := s.d.Cmd("run", "-d", "--log-driver=none", "busybox", "echo", "testline") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| id := strings.TrimSpace(out) | |
| - if out, err := s.d.Cmd("wait", id); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("wait", id) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") | |
| - if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) { | |
| - c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err) | |
| - } | |
| + _, err = os.Stat(logPath) | |
| + c.Assert(err, checker.NotNil, check.Commentf("%s shouldn't exits", logPath)) | |
| + c.Assert(os.IsNotExist(err), checker.True, check.Commentf("%s shouldn't exits, err:%v", logPath, err)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLoggingDriverNone(c *check.C) { | |
| - if err := s.d.StartWithBusybox("--log-driver=none"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox("--log-driver=none"), checker.IsNil, check.Commentf("Could not start daemon")) | |
| out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| id := strings.TrimSpace(out) | |
| - if out, err := s.d.Cmd("wait", id); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("wait", id) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| logPath := filepath.Join(s.d.folder, "graph", "containers", id, id+"-json.log") | |
| - if _, err := os.Stat(logPath); err == nil || !os.IsNotExist(err) { | |
| - c.Fatalf("%s shouldn't exits, error on Stat: %s", logPath, err) | |
| - } | |
| + _, err = os.Stat(logPath) | |
| + c.Assert(err, checker.NotNil, check.Commentf("%s shouldn't exits", logPath)) | |
| + c.Assert(os.IsNotExist(err), checker.True, check.Commentf("%s shouldn't exits, err:%v", logPath, err)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneOverride(c *check.C) { | |
| - if err := s.d.StartWithBusybox("--log-driver=none"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox("--log-driver=none"), checker.IsNil, check.Commentf("Could not start daemon")) | |
| out, err := s.d.Cmd("run", "-d", "--log-driver=json-file", "busybox", "echo", "testline") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| id := strings.TrimSpace(out) | |
| - if out, err := s.d.Cmd("wait", id); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + s.d.Cmd("wait", id) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| logPath := filepath.Join(s.d.root, "containers", id, id+"-json.log") | |
| - if _, err := os.Stat(logPath); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + _, err = os.Stat(logPath) | |
| + c.Assert(err, checker.IsNil) | |
| + | |
| f, err := os.Open(logPath) | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil) | |
| + | |
| var res struct { | |
| Log string `json:"log"` | |
| Stream string `json:"stream"` | |
| Time time.Time `json:"time"` | |
| } | |
| - if err := json.NewDecoder(f).Decode(&res); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| - if res.Log != "testline\n" { | |
| - c.Fatalf("Unexpected log line: %q, expected: %q", res.Log, "testline\n") | |
| - } | |
| - if res.Stream != "stdout" { | |
| - c.Fatalf("Unexpected stream: %q, expected: %q", res.Stream, "stdout") | |
| - } | |
| - if !time.Now().After(res.Time) { | |
| - c.Fatalf("Log time %v in future", res.Time) | |
| - } | |
| + | |
| + c.Assert(json.NewDecoder(f).Decode(&res), checker.IsNil, check.Commentf("Fail to decode %v", f)) | |
| + c.Assert(res.Log, checker.Contains, "testline") | |
| + | |
| + c.Assert(res.Stream, checker.Equals, "stdout") | |
| + c.Assert(time.Now(), checker.IsAfter, res.Time, check.Commentf("Log time in future")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonLoggingDriverNoneLogsError(c *check.C) { | |
| - if err := s.d.StartWithBusybox("--log-driver=none"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox("--log-driver=none"), checker.IsNil, check.Commentf("Could not start daemon")) | |
| out, err := s.d.Cmd("run", "-d", "busybox", "echo", "testline") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| id := strings.TrimSpace(out) | |
| out, err = s.d.Cmd("logs", id) | |
| - if err != nil { | |
| - c.Fatalf("Logs request should be sent and then fail with \"none\" driver") | |
| - } | |
| - if !strings.Contains(out, `Error running logs job: Failed to get logging factory: logger: no log driver named 'none' is registered`) { | |
| - c.Fatalf("There should be an error about none not being a recognized log driver, got: %s", out) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Logs request should be sent and then fail with \"none\" driver")) | |
| + c.Assert(out, checker.Contains, `Error running logs job: Failed to get logging factory: logger: no log driver named 'none' is registered`, check.Commentf("There should be an error about none not being a recognized log driver")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonDots(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| // Now create 4 containers | |
| - if _, err := s.d.Cmd("create", "busybox"); err != nil { | |
| - c.Fatalf("Error creating container: %q", err) | |
| - } | |
| - if _, err := s.d.Cmd("create", "busybox"); err != nil { | |
| - c.Fatalf("Error creating container: %q", err) | |
| - } | |
| - if _, err := s.d.Cmd("create", "busybox"); err != nil { | |
| - c.Fatalf("Error creating container: %q", err) | |
| - } | |
| - if _, err := s.d.Cmd("create", "busybox"); err != nil { | |
| - c.Fatalf("Error creating container: %q", err) | |
| - } | |
| + _, err := s.d.Cmd("create", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error creating container")) | |
| + _, err = s.d.Cmd("create", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error creating container")) | |
| + _, err = s.d.Cmd("create", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error creating container")) | |
| + _, err = s.d.Cmd("create", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error creating container")) | |
| s.d.Stop() | |
| s.d.Start("--log-level=debug") | |
| s.d.Stop() | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if strings.Contains(string(content), "....") { | |
| - c.Fatalf("Debug level should not have ....\n%s", string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Not(checker.Contains), "....", check.Commentf("Debug level should have ....\n")) | |
| s.d.Start("--log-level=error") | |
| s.d.Stop() | |
| content, _ = ioutil.ReadFile(s.d.logFile.Name()) | |
| - if strings.Contains(string(content), "....") { | |
| - c.Fatalf("Error level should not have ....\n%s", string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Not(checker.Contains), "....", check.Commentf("Error level should have ....\n")) | |
| s.d.Start("--log-level=info") | |
| s.d.Stop() | |
| content, _ = ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), "....") { | |
| - c.Fatalf("Info level should have ....\n%s", string(content)) | |
| - } | |
| + c.Assert(string(content), checker.Contains, "....", check.Commentf("Info level should have ....\n")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonUnixSockCleanedUp(c *check.C) { | |
| dir, err := ioutil.TempDir("", "socket-cleanup-test") | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil) | |
| defer os.RemoveAll(dir) | |
| sockPath := filepath.Join(dir, "docker.sock") | |
| - if err := s.d.Start("--host", "unix://"+sockPath); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Start("--host", "unix://"+sockPath), checker.IsNil) | |
| - if _, err := os.Stat(sockPath); err != nil { | |
| - c.Fatal("socket does not exist") | |
| - } | |
| + _, err = os.Stat(sockPath) | |
| + c.Assert(err, checker.IsNil, check.Commentf("socket does not exist")) | |
| - if err := s.d.Stop(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Stop(), checker.IsNil) | |
| - if _, err := os.Stat(sockPath); err == nil || !os.IsNotExist(err) { | |
| - c.Fatal("unix socket is not cleaned up") | |
| - } | |
| + _, err = os.Stat(sockPath) | |
| + c.Assert(err, checker.NotNil, check.Commentf("unix socket is not cleaned up")) | |
| + c.Assert(os.IsNotExist(err), checker.True, check.Commentf("unix socket is not cleaned up")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) { | |
| @@ -1285,70 +1059,49 @@ func (s *DockerDaemonSuite) TestDaemonWithWrongkey(c *check.C) { | |
| } | |
| os.Remove("/etc/docker/key.json") | |
| - if err := s.d.Start(); err != nil { | |
| - c.Fatalf("Failed to start daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Start(), checker.IsNil, check.Commentf("Failed to start daemon")) | |
| - if err := s.d.Stop(); err != nil { | |
| - c.Fatalf("Could not stop daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Stop(), checker.IsNil, check.Commentf("Could not stop daemon")) | |
| config := &Config{} | |
| bytes, err := ioutil.ReadFile("/etc/docker/key.json") | |
| - if err != nil { | |
| - c.Fatalf("Error reading key.json file: %s", err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error reading key.json file")) | |
| // byte[] to Data-Struct | |
| - if err := json.Unmarshal(bytes, &config); err != nil { | |
| - c.Fatalf("Error Unmarshal: %s", err) | |
| - } | |
| + c.Assert(json.Unmarshal(bytes, &config), checker.IsNil, check.Commentf("Error Unmarshal")) | |
| //replace config.Kid with the fake value | |
| config.Kid = "VSAJ:FUYR:X3H2:B2VZ:KZ6U:CJD5:K7BX:ZXHY:UZXT:P4FT:MJWG:HRJ4" | |
| // NEW Data-Struct to byte[] | |
| newBytes, err := json.Marshal(&config) | |
| - if err != nil { | |
| - c.Fatalf("Error Marshal: %s", err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error Marshal")) | |
| // write back | |
| - if err := ioutil.WriteFile("/etc/docker/key.json", newBytes, 0400); err != nil { | |
| - c.Fatalf("Error ioutil.WriteFile: %s", err) | |
| - } | |
| + err = ioutil.WriteFile("/etc/docker/key.json", newBytes, 0400) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error ioutil.WriteFile")) | |
| defer os.Remove("/etc/docker/key.json") | |
| - if err := s.d.Start(); err == nil { | |
| - c.Fatalf("It should not be successful to start daemon with wrong key: %v", err) | |
| - } | |
| + c.Assert(s.d.Start(), checker.NotNil, check.Commentf("It should not be successful to start daemon with wrong key")) | |
| content, _ := ioutil.ReadFile(s.d.logFile.Name()) | |
| - if !strings.Contains(string(content), "Public Key ID does not match") { | |
| - c.Fatal("Missing KeyID message from daemon logs") | |
| - } | |
| + c.Assert(string(content), checker.Contains, "Public Key ID does not match", check.Commentf("Missing KeyID message from daemon logs")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| out, err := s.d.Cmd("run", "-id", "busybox", "/bin/cat") | |
| - if err != nil { | |
| - c.Fatalf("Could not run /bin/cat: err=%v\n%s", err, out) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not run /bin/cat : %s", out)) | |
| + | |
| containerID := strings.TrimSpace(out) | |
| - if out, err := s.d.Cmd("kill", containerID); err != nil { | |
| - c.Fatalf("Could not kill %s: err=%v\n%s", containerID, err, out) | |
| - } | |
| + out, err = s.d.Cmd("kill", containerID) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not kill %s, %s", containerID, out)) | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatalf("Could not restart daemon: %v", err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil, check.Commentf("Could not restart daemon")) | |
| errchan := make(chan error) | |
| go func() { | |
| @@ -1362,9 +1115,7 @@ func (s *DockerDaemonSuite) TestDaemonRestartKillWait(c *check.C) { | |
| case <-time.After(5 * time.Second): | |
| c.Fatal("Waiting on a stopped (killed) container timed out") | |
| case err := <-errchan: | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil) | |
| } | |
| } | |
| @@ -1374,24 +1125,20 @@ func (s *DockerDaemonSuite) TestHttpsInfo(c *check.C) { | |
| testDaemonHTTPSAddr = "tcp://localhost:4271" | |
| ) | |
| - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", | |
| - "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", | |
| + "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr), checker.IsNil, | |
| + check.Commentf("Could not start daemon with busybox")) | |
| daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-cert.pem", "--tlskey", "fixtures/https/client-key.pem"} | |
| out, err := s.d.CmdWithArgs(daemonArgs, "info") | |
| - if err != nil { | |
| - c.Fatalf("Error Occurred: %s and output: %s", err, out) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| } | |
| // TestTlsVerify verifies that --tlsverify=false turns on tls | |
| func (s *DockerDaemonSuite) TestTlsVerify(c *check.C) { | |
| out, err := exec.Command(dockerBinary, "daemon", "--tlsverify=false").CombinedOutput() | |
| - if err == nil || !strings.Contains(string(out), "Could not load X509 key pair") { | |
| - c.Fatalf("Daemon should not have started due to missing certs: %v\n%s", err, string(out)) | |
| - } | |
| + c.Assert(err, checker.NotNil, check.Commentf("Daemon should not have started due to missing certs: %s", string(out))) | |
| + c.Assert(string(out), checker.Contains, "Could not load X509 key pair", check.Commentf("Daemon should not have started due to missing certs")) | |
| } | |
| // TestHttpsInfoRogueCert connects via two-way authenticated HTTPS to the info endpoint | |
| @@ -1402,16 +1149,15 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueCert(c *check.C) { | |
| testDaemonHTTPSAddr = "tcp://localhost:4271" | |
| ) | |
| - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", | |
| - "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-cert.pem", | |
| + "--tlskey", "fixtures/https/server-key.pem", "-H", testDaemonHTTPSAddr), | |
| + checker.IsNil, | |
| + check.Commentf("Could not start daemon with busybox")) | |
| daemonArgs := []string{"--host", testDaemonHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"} | |
| out, err := s.d.CmdWithArgs(daemonArgs, "info") | |
| - if err == nil || !strings.Contains(out, errBadCertificate) { | |
| - c.Fatalf("Expected err: %s, got instead: %s and output: %s", errBadCertificate, err, out) | |
| - } | |
| + c.Assert(err, checker.NotNil, check.Commentf("Daemon should not have started")) | |
| + c.Assert(out, checker.Contains, errBadCertificate) | |
| } | |
| // TestHttpsInfoRogueServerCert connects via two-way authenticated HTTPS to the info endpoint | |
| @@ -1421,16 +1167,15 @@ func (s *DockerDaemonSuite) TestHttpsInfoRogueServerCert(c *check.C) { | |
| errCaUnknown = "x509: certificate signed by unknown authority" | |
| testDaemonRogueHTTPSAddr = "tcp://localhost:4272" | |
| ) | |
| - if err := s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem", | |
| - "--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHTTPSAddr); err != nil { | |
| - c.Fatalf("Could not start daemon with busybox: %v", err) | |
| - } | |
| + c.Assert(s.d.Start("--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/server-rogue-cert.pem", | |
| + "--tlskey", "fixtures/https/server-rogue-key.pem", "-H", testDaemonRogueHTTPSAddr), | |
| + checker.IsNil, | |
| + check.Commentf("Could not start daemon with busybox")) | |
| daemonArgs := []string{"--host", testDaemonRogueHTTPSAddr, "--tlsverify", "--tlscacert", "fixtures/https/ca.pem", "--tlscert", "fixtures/https/client-rogue-cert.pem", "--tlskey", "fixtures/https/client-rogue-key.pem"} | |
| out, err := s.d.CmdWithArgs(daemonArgs, "info") | |
| - if err == nil || !strings.Contains(out, errCaUnknown) { | |
| - c.Fatalf("Expected err: %s, got instead: %s and output: %s", errCaUnknown, err, out) | |
| - } | |
| + c.Assert(err, checker.NotNil, check.Commentf("Daemon should not have started")) | |
| + c.Assert(out, checker.Contains, errCaUnknown) | |
| } | |
| func pingContainers(c *check.C, d *Daemon, expectFailure bool) { | |
| @@ -1450,7 +1195,7 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) { | |
| if expectFailure { | |
| c.Assert(err, check.NotNil) | |
| } else { | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| } | |
| args = append(dargs, "rm", "-f", "container1") | |
| @@ -1458,192 +1203,165 @@ func pingContainers(c *check.C, d *Daemon, expectFailure bool) { | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithSocketAsVolume(c *check.C) { | |
| - c.Assert(s.d.StartWithBusybox(), check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil) | |
| socket := filepath.Join(s.d.folder, "docker.sock") | |
| out, err := s.d.Cmd("run", "-d", "--restart=always", "-v", socket+":/sock", "busybox") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| - c.Assert(s.d.Restart(), check.IsNil) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| } | |
| func (s *DockerDaemonSuite) TestCleanupMountsAfterCrash(c *check.C) { | |
| - c.Assert(s.d.StartWithBusybox(), check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil) | |
| out, err := s.d.Cmd("run", "-d", "busybox", "top") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| id := strings.TrimSpace(out) | |
| - c.Assert(s.d.cmd.Process.Signal(os.Kill), check.IsNil) | |
| - c.Assert(s.d.Start(), check.IsNil) | |
| + c.Assert(s.d.cmd.Process.Signal(os.Kill), checker.IsNil) | |
| + c.Assert(s.d.Start(), checker.IsNil) | |
| mountOut, err := ioutil.ReadFile("/proc/self/mountinfo") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", mountOut)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", mountOut)) | |
| comment := check.Commentf("%s is still mounted from older daemon start:\nDaemon root repository %s\n%s", id, s.d.folder, mountOut) | |
| - c.Assert(strings.Contains(string(mountOut), id), check.Equals, false, comment) | |
| + c.Assert(string(mountOut), checker.Not(checker.Contains), id, comment) | |
| } | |
| func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) { | |
| testRequires(c, NativeExecDriver, NotUserNamespace) | |
| - c.Assert(s.d.StartWithBusybox("-b", "none"), check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox("-b", "none"), checker.IsNil) | |
| out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| - c.Assert(strings.Contains(out, "eth0"), check.Equals, false, | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(out, checker.Not(checker.Contains), "eth0", | |
| check.Commentf("There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled: %s", out)) | |
| out, err = s.d.Cmd("run", "--rm", "--net=bridge", "busybox", "ip", "l") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| - c.Assert(strings.Contains(out, "eth0"), check.Equals, false, | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(out, checker.Not(checker.Contains), "eth0", | |
| check.Commentf("There shouldn't be eth0 in container in bridge mode when bridge network is disabled: %s", out)) | |
| + | |
| cmd := exec.Command("ip", "l") | |
| stdout := bytes.NewBuffer(nil) | |
| cmd.Stdout = stdout | |
| - if err := cmd.Run(); err != nil { | |
| - c.Fatal("Failed to get host network interface") | |
| - } | |
| + c.Assert(cmd.Run(), checker.IsNil, check.Commentf("Failed to get host network interface")) | |
| + | |
| out, err = s.d.Cmd("run", "--rm", "--net=host", "busybox", "ip", "l") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| - c.Assert(out, check.Equals, fmt.Sprintf("%s", stdout), | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(out, checker.Equals, fmt.Sprintf("%s", stdout), | |
| check.Commentf("The network interfaces in container should be the same with host when --net=host when bridge network is disabled: %s", out)) | |
| } | |
| -func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - t.Fatal(err) | |
| - } | |
| - if out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox"); err != nil { | |
| - t.Fatal(out, err) | |
| - } | |
| +func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(c *check.C) { | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| + out, err := s.d.Cmd("run", "-ti", "-d", "--name", "test", "busybox") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| - if err := s.d.Restart(); err != nil { | |
| - t.Fatal(err) | |
| - } | |
| // Container 'test' should be removed without error | |
| - if out, err := s.d.Cmd("rm", "test"); err != nil { | |
| - t.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("rm", "test") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartCleanupNetns(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| out, err := s.d.Cmd("run", "--name", "netns", "-d", "busybox", "top") | |
| - if err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| // Get sandbox key via inspect | |
| out, err = s.d.Cmd("inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", "netns") | |
| - if err != nil { | |
| - c.Fatalf("Error inspecting container: %s, %v", out, err) | |
| - } | |
| + c.Assert(err, checker.IsNil, check.Commentf("Error inspecting container: %s", out)) | |
| + | |
| fileName := strings.Trim(out, " \r\n'") | |
| - if out, err := s.d.Cmd("stop", "netns"); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("stop", "netns") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| // Test if the file still exists | |
| out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) | |
| out = strings.TrimSpace(out) | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| - c.Assert(out, check.Equals, fileName, check.Commentf("Output: %s", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(out, checker.Equals, fileName, check.Commentf("Output: %s", out)) | |
| // Remove the container and restart the daemon | |
| - if out, err := s.d.Cmd("rm", "netns"); err != nil { | |
| - c.Fatal(out, err) | |
| - } | |
| + out, err = s.d.Cmd("rm", "netns") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| // Test again and see now the netns file does not exist | |
| out, _, err = runCommandWithOutput(exec.Command("stat", "-c", "%n", fileName)) | |
| out = strings.TrimSpace(out) | |
| - c.Assert(err, check.Not(check.IsNil), check.Commentf("Output: %s", out)) | |
| + c.Assert(err, checker.NotNil, check.Commentf("Output: %s", out)) | |
| } | |
| // tests regression detailed in #13964 where DOCKER_TLS_VERIFY env is ignored | |
| func (s *DockerDaemonSuite) TestDaemonNoTlsCliTlsVerifyWithEnv(c *check.C) { | |
| host := "tcp://localhost:4271" | |
| - c.Assert(s.d.Start("-H", host), check.IsNil) | |
| + c.Assert(s.d.Start("-H", host), checker.IsNil) | |
| cmd := exec.Command(dockerBinary, "-H", host, "info") | |
| cmd.Env = []string{"DOCKER_TLS_VERIFY=1", "DOCKER_CERT_PATH=fixtures/https"} | |
| out, _, err := runCommandWithOutput(cmd) | |
| - c.Assert(err, check.Not(check.IsNil), check.Commentf("%s", out)) | |
| - c.Assert(strings.Contains(out, "error occurred trying to connect"), check.Equals, true) | |
| + c.Assert(err, checker.NotNil, check.Commentf("%s", out)) | |
| + c.Assert(out, checker.Contains, "error occurred trying to connect") | |
| } | |
| -func setupV6() error { | |
| +func setupV6(c *check.C) { | |
| // Hack to get the right IPv6 address on docker0, which has already been created | |
| err := exec.Command("ip", "addr", "add", "fe80::1/64", "dev", "docker0").Run() | |
| - if err != nil { | |
| - return err | |
| - } | |
| - return nil | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not set up host for IPv6 tests")) | |
| } | |
| -func teardownV6() error { | |
| +func teardownV6(c *check.C) { | |
| err := exec.Command("ip", "addr", "del", "fe80::1/64", "dev", "docker0").Run() | |
| - if err != nil { | |
| - return err | |
| - } | |
| - return nil | |
| + c.Assert(err, checker.IsNil, check.Commentf("Could not perform teardown for IPv6 tests")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithContainerWithRestartPolicyAlways(c *check.C) { | |
| - c.Assert(s.d.StartWithBusybox(), check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil) | |
| out, err := s.d.Cmd("run", "-d", "--restart", "always", "busybox", "top") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| id := strings.TrimSpace(out) | |
| _, err = s.d.Cmd("stop", id) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| _, err = s.d.Cmd("wait", id) | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| out, err = s.d.Cmd("ps", "-q") | |
| - c.Assert(err, check.IsNil) | |
| - c.Assert(out, check.Equals, "") | |
| + c.Assert(err, checker.IsNil) | |
| + c.Assert(out, checker.Equals, "") | |
| - c.Assert(s.d.Restart(), check.IsNil) | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| out, err = s.d.Cmd("ps", "-q") | |
| - c.Assert(err, check.IsNil) | |
| - c.Assert(strings.TrimSpace(out), check.Equals, id[:12]) | |
| + c.Assert(err, checker.IsNil) | |
| + c.Assert(strings.TrimSpace(out), checker.Equals, id[:12]) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonWideLogConfig(c *check.C) { | |
| - if err := s.d.StartWithBusybox("--log-driver=json-file", "--log-opt=max-size=1k"); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox("--log-driver=json-file", "--log-opt=max-size=1k"), checker.IsNil) | |
| + | |
| out, err := s.d.Cmd("run", "-d", "--name=logtest", "busybox", "top") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s, err: %v", out, err)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s, err: %v", out, err)) | |
| out, err = s.d.Cmd("inspect", "-f", "{{ .HostConfig.LogConfig.Config }}", "logtest") | |
| - c.Assert(err, check.IsNil, check.Commentf("Output: %s", out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out)) | |
| cfg := strings.TrimSpace(out) | |
| - if cfg != "map[max-size:1k]" { | |
| - c.Fatalf("Unexpected log-opt: %s, expected map[max-size:1k]", cfg) | |
| - } | |
| + c.Assert(cfg, checker.Equals, "map[max-size:1k]", check.Commentf("Unexpected log-opt")) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartWithPausedContainer(c *check.C) { | |
| - if err := s.d.StartWithBusybox(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| - if out, err := s.d.Cmd("run", "-i", "-d", "--name", "test", "busybox", "top"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| - if out, err := s.d.Cmd("pause", "test"); err != nil { | |
| - c.Fatal(err, out) | |
| - } | |
| - if err := s.d.Restart(); err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil, check.Commentf("Could not start daemon with busybox")) | |
| + out, err := s.d.Cmd("run", "-i", "-d", "--name", "test", "busybox", "top") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| + out, err = s.d.Cmd("pause", "test") | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| + | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| errchan := make(chan error) | |
| go func() { | |
| @@ -1662,34 +1380,32 @@ func (s *DockerDaemonSuite) TestDaemonRestartWithPausedContainer(c *check.C) { | |
| case <-time.After(5 * time.Second): | |
| c.Fatal("Waiting on start a container timed out") | |
| case err := <-errchan: | |
| - if err != nil { | |
| - c.Fatal(err) | |
| - } | |
| + c.Assert(err, checker.IsNil) | |
| } | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartRmVolumeInUse(c *check.C) { | |
| - c.Assert(s.d.StartWithBusybox(), check.IsNil) | |
| + c.Assert(s.d.StartWithBusybox(), checker.IsNil) | |
| out, err := s.d.Cmd("create", "-v", "test:/foo", "busybox") | |
| - c.Assert(err, check.IsNil, check.Commentf(out)) | |
| + c.Assert(err, checker.IsNil, check.Commentf(out)) | |
| - c.Assert(s.d.Restart(), check.IsNil) | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| out, err = s.d.Cmd("volume", "rm", "test") | |
| - c.Assert(err, check.Not(check.IsNil), check.Commentf("should not be able to remove in use volume after daemon restart")) | |
| - c.Assert(strings.Contains(out, "in use"), check.Equals, true) | |
| + c.Assert(err, checker.NotNil, check.Commentf("should not be able to remove in use volume after daemon restart")) | |
| + c.Assert(out, checker.Contains, "in use") | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonRestartLocalVolumes(c *check.C) { | |
| - c.Assert(s.d.Start(), check.IsNil) | |
| + c.Assert(s.d.Start(), checker.IsNil) | |
| _, err := s.d.Cmd("volume", "create", "--name", "test") | |
| - c.Assert(err, check.IsNil) | |
| - c.Assert(s.d.Restart(), check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| + c.Assert(s.d.Restart(), checker.IsNil) | |
| _, err = s.d.Cmd("volume", "inspect", "test") | |
| - c.Assert(err, check.IsNil) | |
| + c.Assert(err, checker.IsNil) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) { | |
| @@ -1698,22 +1414,20 @@ func (s *DockerDaemonSuite) TestDaemonCorruptedLogDriverAddress(c *check.C) { | |
| "gelf", | |
| } { | |
| args := []string{"--log-driver=" + driver, "--log-opt", driver + "-address=corrupted:42"} | |
| - c.Assert(s.d.Start(args...), check.NotNil, check.Commentf(fmt.Sprintf("Expected daemon not to start with invalid %s-address provided", driver))) | |
| + c.Assert(s.d.Start(args...), checker.NotNil, check.Commentf(fmt.Sprintf("Expected daemon not to start with invalid %s-address provided", driver))) | |
| expected := fmt.Sprintf("Failed to set log opts: %s-address should be in form proto://address", driver) | |
| runCmd := exec.Command("grep", expected, s.d.LogfileName()) | |
| - if out, _, err := runCommandWithOutput(runCmd); err != nil { | |
| - c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err) | |
| - } | |
| + out, _, err := runCommandWithOutput(runCmd) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Expected %q message; but doesn't exist in log: %q", expected, out)) | |
| } | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonCorruptedFluentdAddress(c *check.C) { | |
| - c.Assert(s.d.Start("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), check.NotNil) | |
| + c.Assert(s.d.Start("--log-driver=fluentd", "--log-opt", "fluentd-address=corrupted:c"), checker.NotNil) | |
| expected := "Failed to set log opts: invalid fluentd-address corrupted:c: " | |
| runCmd := exec.Command("grep", expected, s.d.LogfileName()) | |
| - if out, _, err := runCommandWithOutput(runCmd); err != nil { | |
| - c.Fatalf("Expected %q message; but doesn't exist in log: %q, err: %v", expected, out, err) | |
| - } | |
| + out, _, err := runCommandWithOutput(runCmd) | |
| + c.Assert(err, checker.IsNil, check.Commentf("Expected %q message; but doesn't exist in log: %q", expected, out)) | |
| } | |
| func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *check.C) { | |
| @@ -1721,5 +1435,5 @@ func (s *DockerDaemonSuite) TestDaemonStartWithoutHost(c *check.C) { | |
| defer func() { | |
| s.d.useDefaultHost = false | |
| }() | |
| - c.Assert(s.d.Start(), check.IsNil) | |
| + c.Assert(s.d.Start(), checker.IsNil) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment