Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit f4e408f

Browse files
committed
[integration-test] append test case for local load
1 parent e772178 commit f4e408f

File tree

3 files changed

+137
-8
lines changed

3 files changed

+137
-8
lines changed

integration-cli/README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,11 +334,17 @@ SECRET_KEY="<hyper secret key>"
334334

335335
```
336336
// run all test cases
337-
$ ./util.sh test
337+
$ ./util.sh test all
338+
339+
// run test case with timeout
340+
$ ./util.sh test all -timout 20m
338341
339342
// run specified test case
340-
$ ./util.sh test TestLoadFromLocalTar$
343+
$ ./util.sh test -check.f ^TestLoadFromLocalTar$
341344
342345
// run test cases start with specified prefix
343-
$ ./util.sh test TestLoadFromLocalTar
346+
$ ./util.sh test -check.f TestLoadFromLocalTar
347+
348+
// combined use
349+
$ ./util.sh test -check.f 'TestLoadFromLocalTarEmpty|TestLoadFromLocalPullAndLoad' -timeout 20m
344350
```

integration-cli/hyper_cli_load_local_test.go

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ func (s *DockerSuite) TestLoadFromLocalTarDelta(c *check.C) {
7474
defer printTestDuration(time.Now())
7575
testRequires(c, DaemonIsLinux)
7676

77-
baseURL := "https://image-tarball.s3.amazonaws.com/test/public/debian_stretch-slim.tar.gz"
77+
baseURL := "http://image-tarball.s3.amazonaws.com/test/public/debian_stretch-slim.tar.gz"
7878
basePath := fmt.Sprintf("%s/debian_stretch-slim.tar.gz", os.Getenv("IMAGE_DIR"))
7979

80-
publicURL := "https://image-tarball.s3.amazonaws.com/test/public/nginx_stable.tar.gz"
80+
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/nginx_stable.tar.gz"
8181
imagePath := fmt.Sprintf("%s/nginx_stable.tar.gz", os.Getenv("IMAGE_DIR"))
8282

8383
//download base image tar
@@ -173,7 +173,7 @@ func (s *DockerSuite) TestLoadFromLocalTarSize100MB(c *check.C) {
173173
defer printTestDuration(time.Now())
174174
testRequires(c, DaemonIsLinux)
175175

176-
publicURL := "https://image-tarball.s3.amazonaws.com/test/public/nginx_stable.tar"
176+
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/nginx_stable.tar"
177177
imagePath := fmt.Sprintf("%s/nginx_stable.tar", os.Getenv("IMAGE_DIR"))
178178

179179
//download image tar
@@ -199,6 +199,68 @@ func (s *DockerSuite) TestLoadFromLocalTarSize100MB(c *check.C) {
199199
c.Assert(images, checker.Contains, "nginx")
200200
}
201201

202+
func (s *DockerSuite) TestLoadFromLocalTarSize600MB(c *check.C) {
203+
printTestCaseName()
204+
defer printTestDuration(time.Now())
205+
testRequires(c, DaemonIsLinux)
206+
207+
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/jenkins.tar"
208+
imagePath := fmt.Sprintf("%s/jenkins.tar", os.Getenv("IMAGE_DIR"))
209+
210+
//download image tar
211+
wgetCmd := exec.Command("wget", "-cO", imagePath, publicURL)
212+
output, exitCode, err := runCommandWithOutput(wgetCmd)
213+
c.Assert(exitCode, checker.Equals, 0)
214+
c.Assert(err, checker.IsNil)
215+
c.Assert(pathExist(imagePath), checker.Equals, true)
216+
217+
//ensure jenkins:latest not exist
218+
dockerCmdWithError("rmi", "jenkins:latest")
219+
images, _ := dockerCmd(c, "images", "jenkins:latest")
220+
c.Assert(images, checker.Not(checker.Contains), "jenkins")
221+
222+
//load image tar
223+
output, exitCode, err = dockerCmdWithError("load", "-i", imagePath)
224+
c.Assert(output, checker.Contains, "has been loaded.")
225+
c.Assert(err, checker.IsNil)
226+
c.Assert(exitCode, checker.Equals, 0)
227+
228+
//check image
229+
images, _ = dockerCmd(c, "images", "jenkins:latest")
230+
c.Assert(images, checker.Contains, "jenkins")
231+
}
232+
233+
func (s *DockerSuite) TestLoadFromLocalPullAndLoad(c *check.C) {
234+
printTestCaseName()
235+
defer printTestDuration(time.Now())
236+
testRequires(c, DaemonIsLinux)
237+
238+
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/debian-8_5.tar.gz"
239+
imagePath := fmt.Sprintf("%s/debian-8_5.tar.gz", os.Getenv("IMAGE_DIR"))
240+
241+
//download image tar
242+
wgetCmd := exec.Command("wget", "-cO", imagePath, publicURL)
243+
output, exitCode, err := runCommandWithOutput(wgetCmd)
244+
c.Assert(exitCode, checker.Equals, 0)
245+
c.Assert(err, checker.IsNil)
246+
c.Assert(pathExist(imagePath), checker.Equals, true)
247+
248+
//ensure debian:8.5 exist
249+
dockerCmdWithError("pull", "debian:8.5")
250+
images, _ := dockerCmd(c, "images", "debian:8.5")
251+
c.Assert(images, checker.Contains, "debian")
252+
253+
//load image tar
254+
output, exitCode, err = dockerCmdWithError("load", "-i", imagePath)
255+
c.Assert(output, checker.Contains, "has been loaded.")
256+
c.Assert(err, checker.IsNil)
257+
c.Assert(exitCode, checker.Equals, 0)
258+
259+
//check image
260+
images, _ = dockerCmd(c, "images", "debian:8.5")
261+
c.Assert(images, checker.Contains, "debian")
262+
}
263+
202264
//test abnormal///////////////////////////////////////////////////////////////////////////
203265
func (s *DockerSuite) TestLoadFromLocalMultipeImage(c *check.C) {
204266
printTestCaseName()
@@ -229,6 +291,47 @@ func (s *DockerSuite) TestLoadFromLocalMultipeImage(c *check.C) {
229291
c.Assert(images, checker.Not(checker.Contains), "alpine")
230292
}
231293

294+
func (s *DockerSuite) TestLoadFromLocalTarEmpty(c *check.C) {
295+
printTestCaseName()
296+
defer printTestDuration(time.Now())
297+
testRequires(c, DaemonIsLinux)
298+
299+
//generate empty image tar
300+
imagePath := fmt.Sprintf("%s/empty.tar", os.Getenv("IMAGE_DIR"))
301+
os.OpenFile(imagePath, os.O_RDONLY|os.O_CREATE, 0666)
302+
f, err := os.OpenFile(imagePath, os.O_CREATE, 0600)
303+
c.Assert(err, checker.IsNil)
304+
f.Close()
305+
306+
//load image tar
307+
output, exitCode, err := dockerCmdWithError("load", "-i", imagePath)
308+
c.Assert(output, checker.Contains, "manifest.json: no such file or directory")
309+
c.Assert(err, checker.NotNil)
310+
c.Assert(exitCode, checker.Not(checker.Equals), 0)
311+
}
312+
313+
func (s *DockerSuite) TestLoadFromLocalTarLegacy(c *check.C) {
314+
printTestCaseName()
315+
defer printTestDuration(time.Now())
316+
testRequires(c, DaemonIsLinux)
317+
318+
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/old/ubuntu_1.8.tar.gz"
319+
imagePath := fmt.Sprintf("%s/ubuntu_1.8.tar.gz", os.Getenv("IMAGE_DIR"))
320+
321+
//download image tar
322+
wgetCmd := exec.Command("wget", "-cO", imagePath, publicURL)
323+
output, exitCode, err := runCommandWithOutput(wgetCmd)
324+
c.Assert(pathExist(imagePath), checker.Equals, true)
325+
c.Assert(exitCode, checker.Equals, 0)
326+
c.Assert(err, checker.IsNil)
327+
328+
//load image tar
329+
output, exitCode, err = dockerCmdWithError("load", "-i", imagePath)
330+
c.Assert(output, checker.Contains, "manifest.json: no such file or directory")
331+
c.Assert(err, checker.NotNil)
332+
c.Assert(exitCode, checker.Not(checker.Equals), 0)
333+
}
334+
232335
/*
233336
// TODO
234337
//Prerequisite: update image balance to 1 in tenant collection of hypernetes in mongodb

integration-cli/util.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ Usage: ./util.sh <action>
1414
EOF
1515
}
1616

17+
function show_test_usage() {
18+
cat <<EOF
19+
---------------------------------------------------------------------------------------------------------------
20+
Usage:
21+
./util.sh test all # run all test case
22+
./util.sh test all -timeout 20m # run all test case with specified timeout(default 10m)
23+
./util.sh test -check.f <case prefix> # run specified test case
24+
./util.sh test -check.f ^<case name>$ # run specified prefix of test case
25+
./util.sh test -check.f <case prefix> -timeout 20m # combined use
26+
----------------------------------------------------------------------------------------------------------------
27+
EOF
28+
}
29+
1730
#############################################################################
1831
WORKDIR=$(cd `dirname $0`; pwd)
1932
cd ${WORKDIR}
@@ -111,9 +124,16 @@ case $1 in
111124
mkdir -p ${IMAGE_DIR}
112125
shift
113126
if [ $# -ne 0 ];then
114-
go test -check.f $@
127+
if [ $1 == "all" ];then
128+
shift
129+
go test $@
130+
elif [ $1 == "-check.f" ];then
131+
go test $@
132+
else
133+
show_test_usage
134+
fi
115135
else
116-
go test
136+
show_test_usage
117137
fi
118138
;;
119139
*) show_usage

0 commit comments

Comments
 (0)