mirror of https://github.com/docker/docs.git
Fix TestRenameStoppedContainer race
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
parent
1b4de6f2e8
commit
cd6cc45d52
|
@ -4,11 +4,11 @@ import (
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -25,7 +25,8 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
||||||
|
|
||||||
name, err := inspectField(cleanedContainerID, "Name")
|
name, err := inspectField(cleanedContainerID, "Name")
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "rename", "first_name", "new_name")
|
newName := "new_name" + stringid.GenerateRandomID()
|
||||||
|
runCmd = exec.Command(dockerBinary, "rename", "first_name", newName)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf(out, err)
|
c.Fatalf(out, err)
|
||||||
|
@ -35,22 +36,22 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
if name != "/new_name" {
|
if name != "/"+newName {
|
||||||
c.Fatal("Failed to rename container ", name)
|
c.Fatal("Failed to rename container ", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
|
func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf(out, err)
|
c.Fatalf(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newName := "new_name" + stringid.GenerateRandomID()
|
||||||
cleanedContainerID := strings.TrimSpace(out)
|
cleanedContainerID := strings.TrimSpace(out)
|
||||||
runCmd = exec.Command(dockerBinary, "rename", "first_name", "new_name")
|
runCmd = exec.Command(dockerBinary, "rename", "first_name", newName)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf(out, err)
|
c.Fatalf(out, err)
|
||||||
|
@ -60,31 +61,30 @@ func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
if name != "/new_name" {
|
if name != "/"+newName {
|
||||||
c.Fatal("Failed to rename container ")
|
c.Fatal("Failed to rename container ")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
|
func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
|
||||||
|
|
||||||
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
runCmd := exec.Command(dockerBinary, "run", "--name", "first_name", "-d", "busybox", "sh")
|
||||||
out, _, err := runCommandWithOutput(runCmd)
|
out, _, err := runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf(out, err)
|
c.Fatalf(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
runCmd = exec.Command(dockerBinary, "rename", "first_name", "new_name")
|
newName := "new_name" + stringid.GenerateRandomID()
|
||||||
|
runCmd = exec.Command(dockerBinary, "rename", "first_name", newName)
|
||||||
out, _, err = runCommandWithOutput(runCmd)
|
out, _, err = runCommandWithOutput(runCmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatalf(out, err)
|
c.Fatalf(out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
name, err := inspectField("new_name", "Name")
|
name, err := inspectField(newName, "Name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
if name != "/new_name" {
|
if name != "/"+newName {
|
||||||
c.Fatal("Failed to rename container ")
|
c.Fatal("Failed to rename container ")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,6 @@ func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
|
||||||
if err == nil && !strings.Contains(err.Error(), "No such image or container: first_name") {
|
if err == nil && !strings.Contains(err.Error(), "No such image or container: first_name") {
|
||||||
c.Fatal(err)
|
c.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
||||||
|
@ -110,5 +109,4 @@ func (s *DockerSuite) TestRenameInvalidName(c *check.C) {
|
||||||
if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "myname") {
|
if out, _, err := runCommandWithOutput(runCmd); err != nil || !strings.Contains(out, "myname") {
|
||||||
c.Fatalf("Output of docker ps should have included 'myname': %s\n%v", out, err)
|
c.Fatalf("Output of docker ps should have included 'myname': %s\n%v", out, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue