11package main
22
33import (
4- "time"
5- "os"
64 "fmt"
75 "github.com/docker/docker/pkg/integration/checker"
86 "github.com/go-check/check"
7+ "os"
8+ "time"
99)
1010
1111/// test invalid url //////////////////////////////////////////////////////////////////////////
1212func (s * DockerSuite ) TestLoadFromInvalidUrlProtocal (c * check.C ) {
13- printTestCaseName (); defer printTestDuration (time .Now ())
13+ printTestCaseName ()
14+ defer printTestDuration (time .Now ())
1415 testRequires (c , DaemonIsLinux )
1516 invalidURL := "ftp://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
1617 output , exitCode , err := dockerCmdWithError ("load" , "-i" , invalidURL )
17- c .Assert (output , checker .Equals , "Error response from daemon: Get " + invalidURL + ": unsupported protocol scheme \" ftp\" \n " )
18+ c .Assert (output , checker .Equals , "Error response from daemon: Bad request parameters: Get " + invalidURL + ": unsupported protocol scheme \" ftp\" \n " )
1819 c .Assert (exitCode , checker .Equals , 1 )
1920 c .Assert (err , checker .NotNil )
2021}
2122
2223func (s * DockerSuite ) TestLoadFromInvalidUrlHost (c * check.C ) {
23- printTestCaseName (); defer printTestDuration (time .Now ())
24+ printTestCaseName ()
25+ defer printTestDuration (time .Now ())
2426 testRequires (c , DaemonIsLinux )
2527 invalidHost := "invalidhost"
2628 invalidURL := "http://" + invalidHost + "/test/public/helloworld.tar"
2729 output , exitCode , err := dockerCmdWithError ("load" , "-i" , invalidURL )
28- c .Assert (output , checker .Equals , "Error response from daemon: Get " + invalidURL + ": dial tcp: lookup invalidhost: no such host\n " )
30+ c .Assert (output , checker .Equals , "Error response from daemon: Bad request parameters: Get " + invalidURL + ": dial tcp: lookup invalidhost: no such host\n " )
2931 c .Assert (exitCode , checker .Equals , 1 )
3032 c .Assert (err , checker .NotNil )
3133}
3234
3335func (s * DockerSuite ) TestLoadFromInvalidUrlPath (c * check.C ) {
34- printTestCaseName (); defer printTestDuration (time .Now ())
36+ printTestCaseName ()
37+ defer printTestDuration (time .Now ())
3538 testRequires (c , DaemonIsLinux )
3639 output , exitCode , err := dockerCmdWithError ("load" , "-i" , "http://image-tarball.s3.amazonaws.com/test/public/notexist.tar" )
37- c .Assert (output , checker .Equals , "Error response from daemon: Got HTTP status code >= 400: 403 Forbidden\n " )
40+ c .Assert (output , checker .Equals , "Error response from daemon: Bad request parameters: Got HTTP status code >= 400: 403 Forbidden\n " )
3841 c .Assert (exitCode , checker .Equals , 1 )
3942 c .Assert (err , checker .NotNil )
4043}
4144
42-
4345//test invalid ContentType and ContentLength///////////////////////////////////////////////////////////////////////////
4446func (s * DockerSuite ) TestLoadFromInvalidContentType (c * check.C ) {
45- printTestCaseName (); defer printTestDuration (time .Now ())
47+ printTestCaseName ()
48+ defer printTestDuration (time .Now ())
4649 testRequires (c , DaemonIsLinux )
4750 output , exitCode , err := dockerCmdWithError ("load" , "-i" , "http://image-tarball.s3.amazonaws.com/test/public/readme.txt" )
48- c .Assert (output , checker .Equals , "Error response from daemon: Download failed: image archive format should be tar, gzip, bzip, or xz \n " )
51+ c .Assert (output , checker .Equals , "Error response from daemon: Download failed: URL MIME type should be one of: binary/octet-stream, application/octet-stream, application/x- tar, application/x- gzip, application/x- bzip, application/x-xz, but now is text/plain \n " )
4952 c .Assert (exitCode , checker .Equals , 1 )
5053 c .Assert (err , checker .NotNil )
5154}
5255
5356func (s * DockerSuite ) TestLoadFromInvalidContentLengthTooLarge (c * check.C ) {
54- printTestCaseName (); defer printTestDuration (time .Now ())
57+ printTestCaseName ()
58+ defer printTestDuration (time .Now ())
5559 testRequires (c , DaemonIsLinux )
5660
5761 const MAX_LENGTH = 4294967295
@@ -63,18 +67,20 @@ func (s *DockerSuite) TestLoadFromInvalidContentLengthTooLarge(c *check.C) {
6367
6468//test invalid content///////////////////////////////////////////////////////////////////////////
6569func (s * DockerSuite ) TestLoadFromInvalidContentLengthZero (c * check.C ) {
66- printTestCaseName (); defer printTestDuration (time .Now ())
70+ printTestCaseName ()
71+ defer printTestDuration (time .Now ())
6772 testRequires (c , DaemonIsLinux )
6873
6974 const MAX_LENGTH = 4294967295
7075 output , exitCode , err := dockerCmdWithError ("load" , "-i" , "http://image-tarball.s3.amazonaws.com/test/public/emptyfile.tar" )
71- c .Assert (output , checker .Equals , fmt .Sprintf ("Error response from daemon: The size of the image archive file is 0, should be greater than zero and less than or equal to %v\n " , MAX_LENGTH ))
76+ c .Assert (output , checker .Equals , fmt .Sprintf ("Error response from daemon: Bad request parameters: The size of the image archive file is 0, should be greater than zero and less than or equal to %v\n " , MAX_LENGTH ))
7277 c .Assert (exitCode , checker .Equals , 1 )
7378 c .Assert (err , checker .NotNil )
7479}
7580
7681func (s * DockerSuite ) TestLoadFromInvalidContentUnrelated (c * check.C ) {
77- printTestCaseName (); defer printTestDuration (time .Now ())
82+ printTestCaseName ()
83+ defer printTestDuration (time .Now ())
7884 testRequires (c , DaemonIsLinux )
7985
8086 output , exitCode , err := dockerCmdWithError ("load" , "-i" , "http://image-tarball.s3.amazonaws.com/test/public/readme.tar" )
@@ -84,7 +90,8 @@ func (s *DockerSuite) TestLoadFromInvalidContentUnrelated(c *check.C) {
8490}
8591
8692func (s * DockerSuite ) TestLoadFromInvalidUntarFail (c * check.C ) {
87- printTestCaseName (); defer printTestDuration (time .Now ())
93+ printTestCaseName ()
94+ defer printTestDuration (time .Now ())
8895 testRequires (c , DaemonIsLinux )
8996
9097 output , exitCode , err := dockerCmdWithError ("load" , "-i" , "http://image-tarball.s3.amazonaws.com/test/public/nottar.tar" )
@@ -94,7 +101,8 @@ func (s *DockerSuite) TestLoadFromInvalidUntarFail(c *check.C) {
94101}
95102
96103func (s * DockerSuite ) TestLoadFromInvalidContentIncomplete (c * check.C ) {
97- printTestCaseName (); defer printTestDuration (time .Now ())
104+ printTestCaseName ()
105+ defer printTestDuration (time .Now ())
98106 testRequires (c , DaemonIsLinux )
99107
100108 deleteAllImages ()
@@ -109,7 +117,6 @@ func (s *DockerSuite) TestLoadFromInvalidContentIncomplete(c *check.C) {
109117
110118 deleteAllImages ()
111119
112-
113120 //// load this image will be OK, but after delete this image, there is a residual image with <none> tag occur.
114121 //url = "http://image-tarball.s3.amazonaws.com/test/public/helloworld-no-manifest.tgz"
115122 //output, exitCode, err = dockerCmdWithError("load", "-i", url)
@@ -122,7 +129,6 @@ func (s *DockerSuite) TestLoadFromInvalidContentIncomplete(c *check.C) {
122129 //
123130 //deleteAllImages()
124131
125-
126132 url = "http://image-tarball.s3.amazonaws.com/test/public/helloworld-no-layer.tgz"
127133 output , exitCode , err = dockerCmdWithError ("load" , "-i" , url )
128134 c .Assert (output , checker .Contains , "json: no such file or directory" )
@@ -137,13 +143,14 @@ func (s *DockerSuite) TestLoadFromInvalidContentIncomplete(c *check.C) {
137143
138144//test normal///////////////////////////////////////////////////////////////////////////
139145func (s * DockerSuite ) TestLoadFromPublicURL (c * check.C ) {
140- printTestCaseName (); defer printTestDuration (time .Now ())
146+ printTestCaseName ()
147+ defer printTestDuration (time .Now ())
141148 testRequires (c , DaemonIsLinux )
142149
143150 publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
144151 output , exitCode , err := dockerCmdWithError ("load" , "-i" , publicURL )
145152 c .Assert (output , checker .Contains , "hello-world:latest(sha256:" )
146- c .Assert (output , checker .HasSuffix , "has been loaded.\n " )
153+ c .Assert (output , checker .Contains , "has been loaded.\n " )
147154 c .Assert (exitCode , checker .Equals , 0 )
148155 c .Assert (err , checker .IsNil )
149156
@@ -152,7 +159,8 @@ func (s *DockerSuite) TestLoadFromPublicURL(c *check.C) {
152159}
153160
154161func (s * DockerSuite ) TestLoadFromCompressedArchive (c * check.C ) {
155- printTestCaseName (); defer printTestDuration (time .Now ())
162+ printTestCaseName ()
163+ defer printTestDuration (time .Now ())
156164 testRequires (c , DaemonIsLinux )
157165
158166 extAry := [... ]string {"tar.gz" , "tgz" , "tar.bz2" , "tar.xz" }
@@ -161,7 +169,7 @@ func (s *DockerSuite) TestLoadFromCompressedArchive(c *check.C) {
161169 publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld." + val
162170 output , exitCode , err := dockerCmdWithError ("load" , "-i" , publicURL )
163171 c .Assert (output , checker .Contains , "hello-world:latest(sha256:" )
164- c .Assert (output , checker .HasSuffix , "has been loaded.\n " )
172+ c .Assert (output , checker .Contains , "has been loaded.\n " )
165173 c .Assert (exitCode , checker .Equals , 0 )
166174 c .Assert (err , checker .IsNil )
167175
@@ -170,7 +178,8 @@ func (s *DockerSuite) TestLoadFromCompressedArchive(c *check.C) {
170178}
171179
172180func (s * DockerSuite ) TestLoadFromPublicURLWithQuiet (c * check.C ) {
173- printTestCaseName (); defer printTestDuration (time .Now ())
181+ printTestCaseName ()
182+ defer printTestDuration (time .Now ())
174183 testRequires (c , DaemonIsLinux )
175184
176185 publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
@@ -182,7 +191,8 @@ func (s *DockerSuite) TestLoadFromPublicURLWithQuiet(c *check.C) {
182191}
183192
184193func (s * DockerSuite ) TestLoadFromPublicURLMultipeImage (c * check.C ) {
185- printTestCaseName (); defer printTestDuration (time .Now ())
194+ printTestCaseName ()
195+ defer printTestDuration (time .Now ())
186196 testRequires (c , DaemonIsLinux )
187197
188198 multiImgURL := "http://image-tarball.s3.amazonaws.com/test/public/busybox_alpine.tar"
@@ -196,7 +206,8 @@ func (s *DockerSuite) TestLoadFromPublicURLMultipeImage(c *check.C) {
196206}
197207
198208func (s * DockerSuite ) TestLoadFromBasicAuthURL (c * check.C ) {
199- printTestCaseName (); defer printTestDuration (time .Now ())
209+ printTestCaseName ()
210+ defer printTestDuration (time .Now ())
200211 testRequires (c , DaemonIsLinux )
201212
202213 urlWithAuth := os .Getenv ("URL_WITH_BASIC_AUTH" )
@@ -209,7 +220,8 @@ func (s *DockerSuite) TestLoadFromBasicAuthURL(c *check.C) {
209220}
210221
211222func (s * DockerSuite ) TestLoadFromAWSS3PreSignedURL (c * check.C ) {
212- printTestCaseName (); defer printTestDuration (time .Now ())
223+ printTestCaseName ()
224+ defer printTestDuration (time .Now ())
213225 testRequires (c , DaemonIsLinux )
214226
215227 deleteAllImages ()
@@ -232,37 +244,41 @@ func (s *DockerSuite) TestLoadFromAWSS3PreSignedURL(c *check.C) {
232244 checkImage (c , true , "cirros" )
233245}
234246
235- //Prerequisite: update image balance to 1 in tenant collection of hypernetes in mongodb
247+ //Prerequisite: update image balance to 2 in tenant collection of hypernetes in mongodb
236248//db.tenant.update({tenantid:"<tenant_id>"},{$set:{"resourceinfo.balance.images":2}})
237249func (s * DockerSuite ) TestLoadFromPublicURLWithQuota (c * check.C ) {
238- printTestCaseName (); defer printTestDuration (time .Now ())
250+ printTestCaseName ()
251+ defer printTestDuration (time .Now ())
239252 testRequires (c , DaemonIsLinux )
240253
241254 deleteAllImages ()
242255
243256 helloworldURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
244257 multiImgURL := "http://image-tarball.s3.amazonaws.com/test/public/busybox_alpine.tar"
245258 ubuntuURL := "http://image-tarball.s3.amazonaws.com/test/public/ubuntu.tar.gz"
246- exceedQuotaMsg := "Exceeded quota, please either delete images, or email support@hyper.sh to request increased quota"
259+ //exceedQuotaMsg := "Exceeded quota, please either delete images, or email support@hyper.sh to request increased quota"
260+ exceedQuotaMsg := "you do not have enough quota"
247261
248262 ///// [init] /////
249- // balance 2 , images 0
263+ // balance 3 , images 0
250264 out , _ := dockerCmd (c , "info" )
251265 c .Assert (out , checker .Contains , "Images: 0" )
252266
253-
254267 ///// [step 1] load new hello-world image /////
255- // balance 2 -> 1, image: 0 -> 1
256- dockerCmd (c , "load" , "-i" , helloworldURL )
257- images , _ := dockerCmd (c , "images" , "hello-world" )
258- c .Assert (images , checker .Contains , "hello-world" )
268+ // balance 3 -> 2, image: 0 -> 1
269+ output , exitCode , err := dockerCmdWithError ("load" , "-i" , helloworldURL )
270+ c .Assert (output , checker .Contains , "has been loaded." )
271+ c .Assert (exitCode , checker .Equals , 0 )
272+ c .Assert (err , checker .IsNil )
273+
274+ checkImage (c , true , "hello-world" )
275+
259276 out , _ = dockerCmd (c , "info" )
260277 c .Assert (out , checker .Contains , "Images: 1" )
261278
262-
263279 ///// [step 2] load hello-world image again /////
264- // balance 1 -> 1 , image 1 -> 1
265- output , exitCode , err : = dockerCmdWithError ("load" , "-i" , helloworldURL )
280+ // balance 2 -> 2 , image 1 -> 1
281+ output , exitCode , err = dockerCmdWithError ("load" , "-i" , helloworldURL )
266282 c .Assert (output , checker .Contains , "has been loaded." )
267283 c .Assert (exitCode , checker .Equals , 0 )
268284 c .Assert (err , checker .IsNil )
@@ -272,87 +288,53 @@ func (s *DockerSuite) TestLoadFromPublicURLWithQuota(c *check.C) {
272288 out , _ = dockerCmd (c , "info" )
273289 c .Assert (out , checker .Contains , "Images: 1" )
274290
275-
276291 ///// [step 3] load multiple image(busybox+alpine) /////
277- // balance 1 -> 0 , image 1 -> 2
292+ // balance 2 -> 2 , image 1 -> 1
278293 output , exitCode , err = dockerCmdWithError ("load" , "-i" , multiImgURL )
279- c .Assert (output , checker .Contains , "has been loaded." )
280294 c .Assert (output , checker .Contains , exceedQuotaMsg )
281295 c .Assert (exitCode , checker .Equals , 1 )
282296 c .Assert (err , checker .NotNil )
283297
284- checkImage (c , true , "busybox" )
298+ checkImage (c , false , "busybox" )
285299 checkImage (c , false , "alpine" )
286300
287301 out , _ = dockerCmd (c , "info" )
288- c .Assert (out , checker .Contains , "Images: 2" )
289-
290-
291- ///// [step 4] load hello-world image again /////
292- // balance 0 -> 0, image 2 -> 2
293- output , exitCode , err = dockerCmdWithError ("load" , "-i" , helloworldURL )
294- c .Assert (output , checker .Contains , exceedQuotaMsg )
295- c .Assert (exitCode , checker .Equals , 1 )
296- c .Assert (err , checker .NotNil )
297-
298- checkImage (c , true , "hello-world" )
299-
300- out , _ = dockerCmd (c , "info" )
301- c .Assert (out , checker .Contains , "Images: 2" )
302-
302+ c .Assert (out , checker .Contains , "Images: 1" )
303303
304- ///// [step 5 ] load new ubuntu image /////
305- // balance 0 -> 0 , image 2 -> 2
304+ ///// [step 4 ] load new ubuntu image /////
305+ // balance 2 -> 1 , image 1 -> 2
306306 output , exitCode , err = dockerCmdWithError ("load" , "-i" , ubuntuURL )
307- c .Assert (output , checker .Contains , exceedQuotaMsg )
308- c .Assert (exitCode , checker .Equals , 1 )
309- c .Assert (err , checker .NotNil )
307+ c .Assert (output , checker .Contains , "has been loaded." )
308+ c .Assert (exitCode , checker .Equals , 0 )
309+ c .Assert (err , checker .IsNil )
310310
311- checkImage (c , false , "ubuntu" )
311+ checkImage (c , true , "ubuntu" )
312312
313313 out , _ = dockerCmd (c , "info" )
314314 c .Assert (out , checker .Contains , "Images: 2" )
315315
316-
317- ///// [step 6] remove hello-world image /////
318- // balance 0 -> 1, image 2 -> 1
319- images , _ = dockerCmd (c , "rmi" , "-f" , "hello-world" )
316+ ///// [step 5] remove hello-world image /////
317+ // balance 1 -> 2, image 2 -> 1
318+ images , _ := dockerCmd (c , "rmi" , "-f" , "hello-world" )
320319 c .Assert (images , checker .Contains , "Untagged: hello-world:latest" )
321320
322321 checkImage (c , false , "hello-world" )
323322
324323 out , _ = dockerCmd (c , "info" )
325324 c .Assert (out , checker .Contains , "Images: 1" )
326325
326+ ///// [step 6] remove busybox and ubuntu image /////
327+ // balance 2 -> 3, image 1 -> 0
328+ images , _ = dockerCmd (c , "rmi" , "-f" , "ubuntu:latest" )
329+ c .Assert (images , checker .Contains , "Untagged: ubuntu:latest" )
327330
328- ///// [step 7] load new ubuntu image again /////
329- //balance 1 -> 0, image 1 -> 2
330- output , exitCode , err = dockerCmdWithError ("load" , "-i" , ubuntuURL )
331- c .Assert (output , checker .Contains , "has been loaded." )
332- c .Assert (exitCode , checker .Equals , 0 )
333- c .Assert (err , checker .IsNil )
334-
335- checkImage (c , true , "ubuntu" )
336-
337- out , _ = dockerCmd (c , "info" )
338- c .Assert (out , checker .Contains , "Images: 2" )
339-
340-
341- ///// [step 8] remove busybox and ubuntu image /////
342- // balance 0 -> 2, image 2 -> 0
343- images , _ = dockerCmd (c , "rmi" , "-f" , "busybox" , "ubuntu:14.04" )
344- c .Assert (images , checker .Contains , "Untagged: busybox:latest" )
345- c .Assert (images , checker .Contains , "Untagged: ubuntu:14.04" )
346-
347- checkImage (c , false , "busybox" )
348331 checkImage (c , false , "ubuntu" )
349332
350333 out , _ = dockerCmd (c , "info" )
351334 c .Assert (out , checker .Contains , "Images: 0" )
352335
353-
354- ///// [step 9] load multiple image(busybox+alpine) again /////
355- // balance 2 -> 0, image 0 -> 2
336+ ///// [step 7] load multiple image(busybox+alpine) again /////
337+ // balance 3 -> 0, image 0 -> 3
356338 output , exitCode , err = dockerCmdWithError ("load" , "-i" , multiImgURL )
357339 c .Assert (output , checker .Contains , "has been loaded." )
358340 c .Assert (exitCode , checker .Equals , 0 )
@@ -362,5 +344,5 @@ func (s *DockerSuite) TestLoadFromPublicURLWithQuota(c *check.C) {
362344 checkImage (c , true , "alpine" )
363345
364346 out , _ = dockerCmd (c , "info" )
365- c .Assert (out , checker .Contains , "Images: 2 " )
347+ c .Assert (out , checker .Contains , "Images: 3 " )
366348}
0 commit comments