integration-cli: docker_cli_build_test: check error before defer

Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
Antonio Murdaca
2015-10-09 18:51:15 +02:00
committed by Tibor Vass
parent 98af0d7f3c
commit 7176e68625
+32 -32
View File
@@ -818,10 +818,10 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
"test_file3": "test3",
"test_file4": "test4",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err := buildImageFromContext(name, ctx, true); err != nil {
c.Fatal(err)
@@ -838,10 +838,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -860,10 +860,10 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFile(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -882,10 +882,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFileWild(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -904,10 +904,10 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFileWild(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -926,10 +926,10 @@ func (s *DockerSuite) TestBuildCopyMultipleFilesToFile(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -948,10 +948,10 @@ func (s *DockerSuite) TestBuildJSONCopyMultipleFilesToFile(c *check.C) {
"file1.txt": "test1",
"file2.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -986,10 +986,10 @@ RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
"test_dir/test_file5": "test5",
"test dir/test_file6": "test6",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err := buildImageFromContext(name, ctx, true); err != nil {
c.Fatal(err)
@@ -1022,10 +1022,10 @@ RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
"test_dir/test_file5": "test5",
"test dir/test_file6": "test6",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err := buildImageFromContext(name, ctx, true); err != nil {
c.Fatal(err)
@@ -1042,10 +1042,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFileWithWhitespace(c *check.C)
"test file1": "test1",
"test file2": "test2",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -1064,10 +1064,10 @@ func (s *DockerSuite) TestBuildCopyMultipleFilesToFileWithWhitespace(c *check.C)
"test file1": "test1",
"test file2": "test2",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -1133,10 +1133,10 @@ func (s *DockerSuite) TestBuildCopyWildcardNoFind(c *check.C) {
ctx, err := fakeContext(`FROM busybox
COPY file*.txt /tmp/
`, nil)
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
_, err = buildImageFromContext(name, ctx, true)
if err == nil {
@@ -1181,10 +1181,10 @@ func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
map[string]string{
"file1.txt": "test1",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
@@ -2213,10 +2213,10 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
_, err = buildImageFromContext(name, ctx, false)
if err != nil {
c.Fatal(err)
@@ -2698,10 +2698,10 @@ func (s *DockerSuite) TestBuildAddLocalFileWithCache(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -2727,10 +2727,10 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithCache(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -2758,10 +2758,10 @@ func (s *DockerSuite) TestBuildAddLocalFileWithoutCache(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -2785,10 +2785,10 @@ func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"dir/foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -2819,10 +2819,10 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -2875,10 +2875,10 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) {
ctx, err := fakeContext(dockerfile, map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
id1, err := buildImageFromContext(name, ctx, true)
if err != nil {
c.Fatal(err)
@@ -3064,10 +3064,10 @@ CMD ["cat", "/foo"]`,
"foo": "bar",
},
)
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
context, err := archive.Tar(ctx.Dir, compression)
if err != nil {
c.Fatalf("failed to build context tar: %v", err)
@@ -3185,10 +3185,10 @@ func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *check.C) {
map[string]string{
"foo": "hello",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err := buildImageFromContext(name, ctx, true); err != nil {
c.Fatal(err)
}
@@ -3212,10 +3212,10 @@ func (s *DockerSuite) TestBuildForbiddenContextPath(c *check.C) {
"test.txt": "test1",
"other.txt": "other",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
expected := "Forbidden path outside the build context: ../../ "
if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
@@ -3230,10 +3230,10 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) {
ctx, err := fakeContext(`FROM scratch
ADD foo /usr/local/bar`,
map[string]string{"bar": "hello"})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err := buildImageFromContext(name, ctx, true); err != nil {
if !strings.Contains(err.Error(), "foo: no such file or directory") {
c.Fatalf("Wrong error %v, must be about missing foo file or directory", err)
@@ -3630,10 +3630,10 @@ func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) {
"Dockerfile": dockerfile,
".dockerignore": ".dockerignore\n",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if _, err = buildImageFromContext(name, ctx, true); err != nil {
c.Fatalf("Didn't ignore .dockerignore correctly:%s", err)
}
@@ -3652,10 +3652,10 @@ func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) {
"Dockerfile": dockerfile,
".dockerignore": "Dockerfile\n",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
if id1, err = buildImageFromContext(name, ctx, true); err != nil {
c.Fatalf("Didn't build it correctly:%s", err)
@@ -4925,10 +4925,10 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
"dFile": "FROM busybox\nRUN echo from dFile",
"files/dFile2": "FROM busybox\nRUN echo from files/dFile2",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
if err != nil {
@@ -5027,10 +5027,10 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) {
map[string]string{
"dockerfile": "FROM busybox\nRUN echo from dockerfile",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
if err != nil {
@@ -5052,10 +5052,10 @@ RUN echo from Dockerfile`,
map[string]string{
"dockerfile": "FROM busybox\nRUN echo from dockerfile",
})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
if err != nil {
@@ -5083,10 +5083,10 @@ RUN find /tmp/`})
ctx, err := fakeContext(`FROM busybox
RUN echo from Dockerfile`,
map[string]string{})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
// Make sure that -f is ignored and that we don't use the Dockerfile
// that's in the current dir
@@ -5108,10 +5108,10 @@ func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) {
ctx, err := fakeContext(`FROM busybox
RUN echo from Dockerfile`,
map[string]string{})
defer ctx.Close()
if err != nil {
c.Fatal(err)
}
defer ctx.Close()
// Make sure that -f is ignored and that we don't use the Dockerfile
// that's in the current dir
@@ -5668,8 +5668,8 @@ func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) {
"nullfile": "test2",
},
)
defer ctx.Close()
c.Assert(err, check.IsNil)
defer ctx.Close()
_, err = buildImageFromContext(name, ctx, true)
c.Assert(err, check.IsNil)