Browse code

integration-cli: docker_cli_build_test: check error before defer

Signed-off-by: Antonio Murdaca <runcom@redhat.com>

Antonio Murdaca authored on 2015/10/10 01:51:15
Showing 1 changed files
... ...
@@ -819,10 +819,10 @@ RUN [ $(ls -l /exists/exists_file | awk '{print $3":"$4}') = 'dockerio:dockerio'
819 819
 			"test_file3": "test3",
820 820
 			"test_file4": "test4",
821 821
 		})
822
-	defer ctx.Close()
823 822
 	if err != nil {
824 823
 		c.Fatal(err)
825 824
 	}
825
+	defer ctx.Close()
826 826
 
827 827
 	if _, err := buildImageFromContext(name, ctx, true); err != nil {
828 828
 		c.Fatal(err)
... ...
@@ -839,10 +839,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFile(c *check.C) {
839 839
 			"file1.txt": "test1",
840 840
 			"file2.txt": "test1",
841 841
 		})
842
-	defer ctx.Close()
843 842
 	if err != nil {
844 843
 		c.Fatal(err)
845 844
 	}
845
+	defer ctx.Close()
846 846
 
847 847
 	expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
848 848
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -861,10 +861,10 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFile(c *check.C) {
861 861
 			"file1.txt": "test1",
862 862
 			"file2.txt": "test1",
863 863
 		})
864
-	defer ctx.Close()
865 864
 	if err != nil {
866 865
 		c.Fatal(err)
867 866
 	}
867
+	defer ctx.Close()
868 868
 
869 869
 	expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
870 870
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -883,10 +883,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFileWild(c *check.C) {
883 883
 			"file1.txt": "test1",
884 884
 			"file2.txt": "test1",
885 885
 		})
886
-	defer ctx.Close()
887 886
 	if err != nil {
888 887
 		c.Fatal(err)
889 888
 	}
889
+	defer ctx.Close()
890 890
 
891 891
 	expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
892 892
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -905,10 +905,10 @@ func (s *DockerSuite) TestBuildJSONAddMultipleFilesToFileWild(c *check.C) {
905 905
 			"file1.txt": "test1",
906 906
 			"file2.txt": "test1",
907 907
 		})
908
-	defer ctx.Close()
909 908
 	if err != nil {
910 909
 		c.Fatal(err)
911 910
 	}
911
+	defer ctx.Close()
912 912
 
913 913
 	expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
914 914
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -927,10 +927,10 @@ func (s *DockerSuite) TestBuildCopyMultipleFilesToFile(c *check.C) {
927 927
 			"file1.txt": "test1",
928 928
 			"file2.txt": "test1",
929 929
 		})
930
-	defer ctx.Close()
931 930
 	if err != nil {
932 931
 		c.Fatal(err)
933 932
 	}
933
+	defer ctx.Close()
934 934
 
935 935
 	expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
936 936
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -949,10 +949,10 @@ func (s *DockerSuite) TestBuildJSONCopyMultipleFilesToFile(c *check.C) {
949 949
 			"file1.txt": "test1",
950 950
 			"file2.txt": "test1",
951 951
 		})
952
-	defer ctx.Close()
953 952
 	if err != nil {
954 953
 		c.Fatal(err)
955 954
 	}
955
+	defer ctx.Close()
956 956
 
957 957
 	expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
958 958
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -987,10 +987,10 @@ RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
987 987
 			"test_dir/test_file5": "test5",
988 988
 			"test dir/test_file6": "test6",
989 989
 		})
990
-	defer ctx.Close()
991 990
 	if err != nil {
992 991
 		c.Fatal(err)
993 992
 	}
993
+	defer ctx.Close()
994 994
 
995 995
 	if _, err := buildImageFromContext(name, ctx, true); err != nil {
996 996
 		c.Fatal(err)
... ...
@@ -1023,10 +1023,10 @@ RUN [ $(cat "/test dir/test_file6") = 'test6' ]`,
1023 1023
 			"test_dir/test_file5": "test5",
1024 1024
 			"test dir/test_file6": "test6",
1025 1025
 		})
1026
-	defer ctx.Close()
1027 1026
 	if err != nil {
1028 1027
 		c.Fatal(err)
1029 1028
 	}
1029
+	defer ctx.Close()
1030 1030
 
1031 1031
 	if _, err := buildImageFromContext(name, ctx, true); err != nil {
1032 1032
 		c.Fatal(err)
... ...
@@ -1043,10 +1043,10 @@ func (s *DockerSuite) TestBuildAddMultipleFilesToFileWithWhitespace(c *check.C)
1043 1043
 			"test file1": "test1",
1044 1044
 			"test file2": "test2",
1045 1045
 		})
1046
-	defer ctx.Close()
1047 1046
 	if err != nil {
1048 1047
 		c.Fatal(err)
1049 1048
 	}
1049
+	defer ctx.Close()
1050 1050
 
1051 1051
 	expected := "When using ADD with more than one source file, the destination must be a directory and end with a /"
1052 1052
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -1065,10 +1065,10 @@ func (s *DockerSuite) TestBuildCopyMultipleFilesToFileWithWhitespace(c *check.C)
1065 1065
 			"test file1": "test1",
1066 1066
 			"test file2": "test2",
1067 1067
 		})
1068
-	defer ctx.Close()
1069 1068
 	if err != nil {
1070 1069
 		c.Fatal(err)
1071 1070
 	}
1071
+	defer ctx.Close()
1072 1072
 
1073 1073
 	expected := "When using COPY with more than one source file, the destination must be a directory and end with a /"
1074 1074
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -1134,10 +1134,10 @@ func (s *DockerSuite) TestBuildCopyWildcardNoFind(c *check.C) {
1134 1134
 	ctx, err := fakeContext(`FROM busybox
1135 1135
 	COPY file*.txt /tmp/
1136 1136
 	`, nil)
1137
-	defer ctx.Close()
1138 1137
 	if err != nil {
1139 1138
 		c.Fatal(err)
1140 1139
 	}
1140
+	defer ctx.Close()
1141 1141
 
1142 1142
 	_, err = buildImageFromContext(name, ctx, true)
1143 1143
 	if err == nil {
... ...
@@ -1182,10 +1182,10 @@ func (s *DockerSuite) TestBuildCopyWildcardCache(c *check.C) {
1182 1182
 		map[string]string{
1183 1183
 			"file1.txt": "test1",
1184 1184
 		})
1185
-	defer ctx.Close()
1186 1185
 	if err != nil {
1187 1186
 		c.Fatal(err)
1188 1187
 	}
1188
+	defer ctx.Close()
1189 1189
 
1190 1190
 	id1, err := buildImageFromContext(name, ctx, true)
1191 1191
 	if err != nil {
... ...
@@ -2214,10 +2214,10 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
2214 2214
 	ctx, err := fakeContext(dockerfile, map[string]string{
2215 2215
 		"foo": "hello",
2216 2216
 	})
2217
-	defer ctx.Close()
2218 2217
 	if err != nil {
2219 2218
 		c.Fatal(err)
2220 2219
 	}
2220
+	defer ctx.Close()
2221 2221
 	_, err = buildImageFromContext(name, ctx, false)
2222 2222
 	if err != nil {
2223 2223
 		c.Fatal(err)
... ...
@@ -2699,10 +2699,10 @@ func (s *DockerSuite) TestBuildAddLocalFileWithCache(c *check.C) {
2699 2699
 	ctx, err := fakeContext(dockerfile, map[string]string{
2700 2700
 		"foo": "hello",
2701 2701
 	})
2702
-	defer ctx.Close()
2703 2702
 	if err != nil {
2704 2703
 		c.Fatal(err)
2705 2704
 	}
2705
+	defer ctx.Close()
2706 2706
 	id1, err := buildImageFromContext(name, ctx, true)
2707 2707
 	if err != nil {
2708 2708
 		c.Fatal(err)
... ...
@@ -2728,10 +2728,10 @@ func (s *DockerSuite) TestBuildAddMultipleLocalFileWithCache(c *check.C) {
2728 2728
 	ctx, err := fakeContext(dockerfile, map[string]string{
2729 2729
 		"foo": "hello",
2730 2730
 	})
2731
-	defer ctx.Close()
2732 2731
 	if err != nil {
2733 2732
 		c.Fatal(err)
2734 2733
 	}
2734
+	defer ctx.Close()
2735 2735
 	id1, err := buildImageFromContext(name, ctx, true)
2736 2736
 	if err != nil {
2737 2737
 		c.Fatal(err)
... ...
@@ -2759,10 +2759,10 @@ func (s *DockerSuite) TestBuildAddLocalFileWithoutCache(c *check.C) {
2759 2759
 	ctx, err := fakeContext(dockerfile, map[string]string{
2760 2760
 		"foo": "hello",
2761 2761
 	})
2762
-	defer ctx.Close()
2763 2762
 	if err != nil {
2764 2763
 		c.Fatal(err)
2765 2764
 	}
2765
+	defer ctx.Close()
2766 2766
 	id1, err := buildImageFromContext(name, ctx, true)
2767 2767
 	if err != nil {
2768 2768
 		c.Fatal(err)
... ...
@@ -2786,10 +2786,10 @@ func (s *DockerSuite) TestBuildCopyDirButNotFile(c *check.C) {
2786 2786
 	ctx, err := fakeContext(dockerfile, map[string]string{
2787 2787
 		"dir/foo": "hello",
2788 2788
 	})
2789
-	defer ctx.Close()
2790 2789
 	if err != nil {
2791 2790
 		c.Fatal(err)
2792 2791
 	}
2792
+	defer ctx.Close()
2793 2793
 	id1, err := buildImageFromContext(name, ctx, true)
2794 2794
 	if err != nil {
2795 2795
 		c.Fatal(err)
... ...
@@ -2820,10 +2820,10 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithCache(c *check.C) {
2820 2820
 	ctx, err := fakeContext(dockerfile, map[string]string{
2821 2821
 		"foo": "hello",
2822 2822
 	})
2823
-	defer ctx.Close()
2824 2823
 	if err != nil {
2825 2824
 		c.Fatal(err)
2826 2825
 	}
2826
+	defer ctx.Close()
2827 2827
 	id1, err := buildImageFromContext(name, ctx, true)
2828 2828
 	if err != nil {
2829 2829
 		c.Fatal(err)
... ...
@@ -2876,10 +2876,10 @@ func (s *DockerSuite) TestBuildAddCurrentDirWithoutCache(c *check.C) {
2876 2876
 	ctx, err := fakeContext(dockerfile, map[string]string{
2877 2877
 		"foo": "hello",
2878 2878
 	})
2879
-	defer ctx.Close()
2880 2879
 	if err != nil {
2881 2880
 		c.Fatal(err)
2882 2881
 	}
2882
+	defer ctx.Close()
2883 2883
 	id1, err := buildImageFromContext(name, ctx, true)
2884 2884
 	if err != nil {
2885 2885
 		c.Fatal(err)
... ...
@@ -3065,10 +3065,10 @@ CMD ["cat", "/foo"]`,
3065 3065
 			"foo": "bar",
3066 3066
 		},
3067 3067
 	)
3068
-	defer ctx.Close()
3069 3068
 	if err != nil {
3070 3069
 		c.Fatal(err)
3071 3070
 	}
3071
+	defer ctx.Close()
3072 3072
 	context, err := archive.Tar(ctx.Dir, compression)
3073 3073
 	if err != nil {
3074 3074
 		c.Fatalf("failed to build context tar: %v", err)
... ...
@@ -3186,10 +3186,10 @@ func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *check.C) {
3186 3186
 		map[string]string{
3187 3187
 			"foo": "hello",
3188 3188
 		})
3189
-	defer ctx.Close()
3190 3189
 	if err != nil {
3191 3190
 		c.Fatal(err)
3192 3191
 	}
3192
+	defer ctx.Close()
3193 3193
 	if _, err := buildImageFromContext(name, ctx, true); err != nil {
3194 3194
 		c.Fatal(err)
3195 3195
 	}
... ...
@@ -3213,10 +3213,10 @@ func (s *DockerSuite) TestBuildForbiddenContextPath(c *check.C) {
3213 3213
 			"test.txt":  "test1",
3214 3214
 			"other.txt": "other",
3215 3215
 		})
3216
-	defer ctx.Close()
3217 3216
 	if err != nil {
3218 3217
 		c.Fatal(err)
3219 3218
 	}
3219
+	defer ctx.Close()
3220 3220
 
3221 3221
 	expected := "Forbidden path outside the build context: ../../ "
3222 3222
 	if _, err := buildImageFromContext(name, ctx, true); err == nil || !strings.Contains(err.Error(), expected) {
... ...
@@ -3231,10 +3231,10 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) {
3231 3231
 	ctx, err := fakeContext(`FROM scratch
3232 3232
         ADD foo /usr/local/bar`,
3233 3233
 		map[string]string{"bar": "hello"})
3234
-	defer ctx.Close()
3235 3234
 	if err != nil {
3236 3235
 		c.Fatal(err)
3237 3236
 	}
3237
+	defer ctx.Close()
3238 3238
 	if _, err := buildImageFromContext(name, ctx, true); err != nil {
3239 3239
 		if !strings.Contains(err.Error(), "foo: no such file or directory") {
3240 3240
 			c.Fatalf("Wrong error %v, must be about missing foo file or directory", err)
... ...
@@ -3631,10 +3631,10 @@ func (s *DockerSuite) TestBuildDockerignoringDockerignore(c *check.C) {
3631 3631
 		"Dockerfile":    dockerfile,
3632 3632
 		".dockerignore": ".dockerignore\n",
3633 3633
 	})
3634
-	defer ctx.Close()
3635 3634
 	if err != nil {
3636 3635
 		c.Fatal(err)
3637 3636
 	}
3637
+	defer ctx.Close()
3638 3638
 	if _, err = buildImageFromContext(name, ctx, true); err != nil {
3639 3639
 		c.Fatalf("Didn't ignore .dockerignore correctly:%s", err)
3640 3640
 	}
... ...
@@ -3653,10 +3653,10 @@ func (s *DockerSuite) TestBuildDockerignoreTouchDockerfile(c *check.C) {
3653 3653
 		"Dockerfile":    dockerfile,
3654 3654
 		".dockerignore": "Dockerfile\n",
3655 3655
 	})
3656
-	defer ctx.Close()
3657 3656
 	if err != nil {
3658 3657
 		c.Fatal(err)
3659 3658
 	}
3659
+	defer ctx.Close()
3660 3660
 
3661 3661
 	if id1, err = buildImageFromContext(name, ctx, true); err != nil {
3662 3662
 		c.Fatalf("Didn't build it correctly:%s", err)
... ...
@@ -4926,10 +4926,10 @@ func (s *DockerSuite) TestBuildRenamedDockerfile(c *check.C) {
4926 4926
 			"dFile":            "FROM busybox\nRUN echo from dFile",
4927 4927
 			"files/dFile2":     "FROM busybox\nRUN echo from files/dFile2",
4928 4928
 		})
4929
-	defer ctx.Close()
4930 4929
 	if err != nil {
4931 4930
 		c.Fatal(err)
4932 4931
 	}
4932
+	defer ctx.Close()
4933 4933
 
4934 4934
 	out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
4935 4935
 	if err != nil {
... ...
@@ -5028,10 +5028,10 @@ func (s *DockerSuite) TestBuildFromMixedcaseDockerfile(c *check.C) {
5028 5028
 		map[string]string{
5029 5029
 			"dockerfile": "FROM busybox\nRUN echo from dockerfile",
5030 5030
 		})
5031
-	defer ctx.Close()
5032 5031
 	if err != nil {
5033 5032
 		c.Fatal(err)
5034 5033
 	}
5034
+	defer ctx.Close()
5035 5035
 
5036 5036
 	out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
5037 5037
 	if err != nil {
... ...
@@ -5053,10 +5053,10 @@ RUN echo from Dockerfile`,
5053 5053
 		map[string]string{
5054 5054
 			"dockerfile": "FROM busybox\nRUN echo from dockerfile",
5055 5055
 		})
5056
-	defer ctx.Close()
5057 5056
 	if err != nil {
5058 5057
 		c.Fatal(err)
5059 5058
 	}
5059
+	defer ctx.Close()
5060 5060
 
5061 5061
 	out, _, err := dockerCmdInDir(c, ctx.Dir, "build", "-t", "test1", ".")
5062 5062
 	if err != nil {
... ...
@@ -5084,10 +5084,10 @@ RUN find /tmp/`})
5084 5084
 	ctx, err := fakeContext(`FROM busybox
5085 5085
 RUN echo from Dockerfile`,
5086 5086
 		map[string]string{})
5087
-	defer ctx.Close()
5088 5087
 	if err != nil {
5089 5088
 		c.Fatal(err)
5090 5089
 	}
5090
+	defer ctx.Close()
5091 5091
 
5092 5092
 	// Make sure that -f is ignored and that we don't use the Dockerfile
5093 5093
 	// that's in the current dir
... ...
@@ -5109,10 +5109,10 @@ func (s *DockerSuite) TestBuildFromStdinWithF(c *check.C) {
5109 5109
 	ctx, err := fakeContext(`FROM busybox
5110 5110
 RUN echo from Dockerfile`,
5111 5111
 		map[string]string{})
5112
-	defer ctx.Close()
5113 5112
 	if err != nil {
5114 5113
 		c.Fatal(err)
5115 5114
 	}
5115
+	defer ctx.Close()
5116 5116
 
5117 5117
 	// Make sure that -f is ignored and that we don't use the Dockerfile
5118 5118
 	// that's in the current dir
... ...
@@ -5669,8 +5669,8 @@ func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) {
5669 5669
 			"nullfile": "test2",
5670 5670
 		},
5671 5671
 	)
5672
-	defer ctx.Close()
5673 5672
 	c.Assert(err, check.IsNil)
5673
+	defer ctx.Close()
5674 5674
 
5675 5675
 	_, err = buildImageFromContext(name, ctx, true)
5676 5676
 	c.Assert(err, check.IsNil)