Signed-off-by: liaoqingwei <liaoqingwei@huawei.com>
| ... | ... |
@@ -8,6 +8,7 @@ import ( |
| 8 | 8 |
"regexp" |
| 9 | 9 |
"strings" |
| 10 | 10 |
|
| 11 |
+ "github.com/docker/docker/pkg/integration/checker" |
|
| 11 | 12 |
"github.com/go-check/check" |
| 12 | 13 |
) |
| 13 | 14 |
|
| ... | ... |
@@ -20,30 +21,20 @@ func (s *DockerSuite) TestImportDisplay(c *check.C) {
|
| 20 | 20 |
exec.Command(dockerBinary, "export", cleanedContainerID), |
| 21 | 21 |
exec.Command(dockerBinary, "import", "-"), |
| 22 | 22 |
) |
| 23 |
- if err != nil {
|
|
| 24 |
- c.Errorf("import failed with errors: %v, output: %q", err, out)
|
|
| 25 |
- } |
|
| 23 |
+ c.Assert(err, checker.IsNil) |
|
| 26 | 24 |
|
| 27 |
- if n := strings.Count(out, "\n"); n != 1 {
|
|
| 28 |
- c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
|
| 29 |
- } |
|
| 30 |
- image := strings.TrimSpace(out) |
|
| 25 |
+ c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
|
|
| 31 | 26 |
|
| 27 |
+ image := strings.TrimSpace(out) |
|
| 32 | 28 |
out, _ = dockerCmd(c, "run", "--rm", image, "true") |
| 33 |
- if out != "" {
|
|
| 34 |
- c.Fatalf("command output should've been nothing, was %q", out)
|
|
| 35 |
- } |
|
| 29 |
+ c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing."))
|
|
| 36 | 30 |
} |
| 37 | 31 |
|
| 38 | 32 |
func (s *DockerSuite) TestImportBadURL(c *check.C) {
|
| 39 | 33 |
testRequires(c, DaemonIsLinux) |
| 40 | 34 |
out, _, err := dockerCmdWithError("import", "http://nourl/bad")
|
| 41 |
- if err == nil {
|
|
| 42 |
- c.Fatal("import was supposed to fail but didn't")
|
|
| 43 |
- } |
|
| 44 |
- if !strings.Contains(out, "dial tcp") {
|
|
| 45 |
- c.Fatalf("expected an error msg but didn't get one:\n%s", out)
|
|
| 46 |
- } |
|
| 35 |
+ c.Assert(err, checker.NotNil, check.Commentf("import was supposed to fail but didn't"))
|
|
| 36 |
+ c.Assert(out, checker.Contains, "dial tcp", check.Commentf("expected an error msg but didn't get one"))
|
|
| 47 | 37 |
} |
| 48 | 38 |
|
| 49 | 39 |
func (s *DockerSuite) TestImportFile(c *check.C) {
|
| ... | ... |
@@ -51,29 +42,21 @@ func (s *DockerSuite) TestImportFile(c *check.C) {
|
| 51 | 51 |
dockerCmd(c, "run", "--name", "test-import", "busybox", "true") |
| 52 | 52 |
|
| 53 | 53 |
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
| 54 |
- if err != nil {
|
|
| 55 |
- c.Fatal("failed to create temporary file", "", err)
|
|
| 56 |
- } |
|
| 54 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
|
| 57 | 55 |
defer os.Remove(temporaryFile.Name()) |
| 58 | 56 |
|
| 59 | 57 |
runCmd := exec.Command(dockerBinary, "export", "test-import") |
| 60 | 58 |
runCmd.Stdout = bufio.NewWriter(temporaryFile) |
| 61 | 59 |
|
| 62 | 60 |
_, err = runCommand(runCmd) |
| 63 |
- if err != nil {
|
|
| 64 |
- c.Fatal("failed to export a container", err)
|
|
| 65 |
- } |
|
| 61 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
|
|
| 66 | 62 |
|
| 67 | 63 |
out, _ := dockerCmd(c, "import", temporaryFile.Name()) |
| 68 |
- if n := strings.Count(out, "\n"); n != 1 {
|
|
| 69 |
- c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
|
| 70 |
- } |
|
| 64 |
+ c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
|
|
| 71 | 65 |
image := strings.TrimSpace(out) |
| 72 | 66 |
|
| 73 | 67 |
out, _ = dockerCmd(c, "run", "--rm", image, "true") |
| 74 |
- if out != "" {
|
|
| 75 |
- c.Fatalf("command output should've been nothing, was %q", out)
|
|
| 76 |
- } |
|
| 68 |
+ c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing."))
|
|
| 77 | 69 |
} |
| 78 | 70 |
|
| 79 | 71 |
func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
| ... | ... |
@@ -81,48 +64,34 @@ func (s *DockerSuite) TestImportFileWithMessage(c *check.C) {
|
| 81 | 81 |
dockerCmd(c, "run", "--name", "test-import", "busybox", "true") |
| 82 | 82 |
|
| 83 | 83 |
temporaryFile, err := ioutil.TempFile("", "exportImportTest")
|
| 84 |
- if err != nil {
|
|
| 85 |
- c.Fatal("failed to create temporary file", "", err)
|
|
| 86 |
- } |
|
| 84 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to create temporary file"))
|
|
| 87 | 85 |
defer os.Remove(temporaryFile.Name()) |
| 88 | 86 |
|
| 89 | 87 |
runCmd := exec.Command(dockerBinary, "export", "test-import") |
| 90 | 88 |
runCmd.Stdout = bufio.NewWriter(temporaryFile) |
| 91 | 89 |
|
| 92 | 90 |
_, err = runCommand(runCmd) |
| 93 |
- if err != nil {
|
|
| 94 |
- c.Fatal("failed to export a container", err)
|
|
| 95 |
- } |
|
| 91 |
+ c.Assert(err, checker.IsNil, check.Commentf("failed to export a container"))
|
|
| 96 | 92 |
|
| 97 | 93 |
message := "Testing commit message" |
| 98 | 94 |
out, _ := dockerCmd(c, "import", "-m", message, temporaryFile.Name()) |
| 99 |
- if n := strings.Count(out, "\n"); n != 1 {
|
|
| 100 |
- c.Fatalf("display is messed up: %d '\\n' instead of 1:\n%s", n, out)
|
|
| 101 |
- } |
|
| 95 |
+ c.Assert(out, checker.Count, "\n", 1, check.Commentf("display is expected 1 '\\n' but didn't"))
|
|
| 102 | 96 |
image := strings.TrimSpace(out) |
| 103 | 97 |
|
| 104 | 98 |
out, _ = dockerCmd(c, "history", image) |
| 105 | 99 |
split := strings.Split(out, "\n") |
| 106 | 100 |
|
| 107 |
- if len(split) != 3 {
|
|
| 108 |
- c.Fatalf("expected 3 lines from image history, got %d", len(split))
|
|
| 109 |
- } |
|
| 101 |
+ c.Assert(split, checker.HasLen, 3, check.Commentf("expected 3 lines from image history"))
|
|
| 110 | 102 |
r := regexp.MustCompile("[\\s]{2,}")
|
| 111 | 103 |
split = r.Split(split[1], -1) |
| 112 | 104 |
|
| 113 |
- if message != split[3] {
|
|
| 114 |
- c.Fatalf("expected %s in commit message, got %s", message, split[3])
|
|
| 115 |
- } |
|
| 105 |
+ c.Assert(message, checker.Equals, split[3], check.Commentf("didn't get expected value in commit message"))
|
|
| 116 | 106 |
|
| 117 | 107 |
out, _ = dockerCmd(c, "run", "--rm", image, "true") |
| 118 |
- if out != "" {
|
|
| 119 |
- c.Fatalf("command output should've been nothing, was %q", out)
|
|
| 120 |
- } |
|
| 108 |
+ c.Assert(out, checker.Equals, "", check.Commentf("command output should've been nothing"))
|
|
| 121 | 109 |
} |
| 122 | 110 |
|
| 123 | 111 |
func (s *DockerSuite) TestImportFileNonExistentFile(c *check.C) {
|
| 124 |
- _, exitCode, err := dockerCmdWithError("import", "example.com/myImage.tar")
|
|
| 125 |
- if exitCode == 0 || err == nil {
|
|
| 126 |
- c.Fatalf("import non-existing file must failed")
|
|
| 127 |
- } |
|
| 112 |
+ _, _, err := dockerCmdWithError("import", "example.com/myImage.tar")
|
|
| 113 |
+ c.Assert(err, checker.NotNil, check.Commentf("import non-existing file must failed"))
|
|
| 128 | 114 |
} |