From f21fb2162eaf1497e34a3cbddc9d51deec2929d1 Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 22 Jan 2016 21:02:39 -0800 Subject: [PATCH] Windows CI: Fix TestRename* Signed-off-by: John Howard --- daemon/rename.go | 16 +++++++++------- integration-cli/docker_cli_rename_test.go | 19 +++++++++++-------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/daemon/rename.go b/daemon/rename.go index eaed577ad6..84c0df3642 100644 --- a/daemon/rename.go +++ b/daemon/rename.go @@ -64,14 +64,16 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error { }() sid = container.NetworkSettings.SandboxID - sb, err = daemon.netController.SandboxByID(sid) - if err != nil { - return err - } + if daemon.netController != nil { + sb, err = daemon.netController.SandboxByID(sid) + if err != nil { + return err + } - err = sb.Rename(strings.TrimPrefix(container.Name, "/")) - if err != nil { - return err + err = sb.Rename(strings.TrimPrefix(container.Name, "/")) + if err != nil { + return err + } } daemon.LogContainerEvent(container, "rename") return nil diff --git a/integration-cli/docker_cli_rename_test.go b/integration-cli/docker_cli_rename_test.go index df0b26862d..d534d1a1fb 100644 --- a/integration-cli/docker_cli_rename_test.go +++ b/integration-cli/docker_cli_rename_test.go @@ -8,8 +8,15 @@ import ( "github.com/go-check/check" ) +var sleepCmd = "/bin/sleep" + +func init() { + if daemonPlatform == "windows" { + sleepCmd = "sleep" + } +} + func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) { - testRequires(c, DaemonIsLinux) out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") cleanedContainerID := strings.TrimSpace(out) @@ -26,7 +33,6 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) { } func (s *DockerSuite) TestRenameRunningContainer(c *check.C) { - testRequires(c, DaemonIsLinux) out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") newName := "new_name" + stringid.GenerateNonCryptoID() @@ -39,8 +45,7 @@ func (s *DockerSuite) TestRenameRunningContainer(c *check.C) { } func (s *DockerSuite) TestRenameRunningContainerAndReuse(c *check.C) { - testRequires(c, DaemonIsLinux) - out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "top") + out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", sleepCmd, "60") c.Assert(waitRun("first_name"), check.IsNil) newName := "new_name" @@ -51,7 +56,7 @@ func (s *DockerSuite) TestRenameRunningContainerAndReuse(c *check.C) { c.Assert(err, checker.IsNil, check.Commentf("Failed to rename container %s", name)) c.Assert(name, checker.Equals, "/"+newName, check.Commentf("Failed to rename container")) - out, _ = dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "top") + out, _ = dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", sleepCmd, "60") c.Assert(waitRun("first_name"), check.IsNil) newContainerID := strings.TrimSpace(out) name, err = inspectField(newContainerID, "Name") @@ -60,7 +65,6 @@ func (s *DockerSuite) TestRenameRunningContainerAndReuse(c *check.C) { } func (s *DockerSuite) TestRenameCheckNames(c *check.C) { - testRequires(c, DaemonIsLinux) dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh") newName := "new_name" + stringid.GenerateNonCryptoID() @@ -76,8 +80,7 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) { } func (s *DockerSuite) TestRenameInvalidName(c *check.C) { - testRequires(c, DaemonIsLinux) - dockerCmd(c, "run", "--name", "myname", "-d", "busybox", "top") + dockerCmd(c, "run", "--name", "myname", "-d", "busybox", sleepCmd, "60") out, _, err := dockerCmdWithError("rename", "myname", "new:invalid") c.Assert(err, checker.NotNil, check.Commentf("Renaming container to invalid name should have failed: %s", out))