This repository was archived by the owner on Feb 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathhyper_cli_load_basic_test.go
More file actions
210 lines (171 loc) · 8.34 KB
/
Copy pathhyper_cli_load_basic_test.go
File metadata and controls
210 lines (171 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package main
import (
"fmt"
"github.com/docker/docker/pkg/integration/checker"
"github.com/go-check/check"
"time"
)
/// test invalid url //////////////////////////////////////////////////////////////////////////
func (s *DockerSuite) TestCliLoadFromUrlInvalidUrlProtocal(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
invalidURL := "ftp://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
output, exitCode, err := dockerCmdWithError("load", "-i", invalidURL)
c.Assert(output, checker.Equals, "Error response from daemon: Bad request parameters: Get "+invalidURL+": unsupported protocol scheme \"ftp\"\n")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidUrlHost(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
invalidHost := "invalidhost"
invalidURL := "http://" + invalidHost + "/test/public/helloworld.tar"
output, exitCode, err := dockerCmdWithError("load", "-i", invalidURL)
c.Assert(output, checker.Contains, "Error response from daemon: Bad request parameters: Get "+invalidURL+": dial tcp: lookup invalidhost")
c.Assert(output, checker.Contains, "no such host\n")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidUrlPath(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/notexist.tar")
c.Assert(output, checker.Equals, "Error response from daemon: Bad request parameters: Got HTTP status code >= 400: 404 Not Found\n")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
//test invalid ContentType and ContentLength///////////////////////////////////////////////////////////////////////////
func (s *DockerSuite) TestCliLoadFromUrlInvalidContentType(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/readme.txt")
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")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidContentLengthTooLarge(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
const MaxLength = 4294967295
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/largefile.tar")
c.Assert(output, checker.Contains, fmt.Sprintf("should be greater than zero and less than or equal to %v\n", MaxLength))
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
//test invalid content///////////////////////////////////////////////////////////////////////////
func (s *DockerSuite) TestCliLoadFromUrlInvalidContentLengthZero(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
const MaxLength = 4294967295
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/emptyfile.tar")
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", MaxLength))
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidContentUnrelated(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/readme.tar")
c.Assert(output, checker.Contains, "invalid argument\n")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidUntarFail(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
output, exitCode, err := dockerCmdWithError("load", "-i", "http://image-tarball.s3.amazonaws.com/test/public/nottar.tar")
c.Assert(output, checker.Contains, "Untar re-exec error: exit status 1: output: unexpected EOF\n")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
}
func (s *DockerSuite) TestCliLoadFromUrlInvalidContentIncomplete(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
deleteAllImages()
url := "http://image-tarball.s3.amazonaws.com/test/public/helloworld-no-repositories.tgz"
output, exitCode, err := dockerCmdWithError("load", "-i", url)
c.Assert(output, checker.Contains, "has been loaded.")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)
images, _ := dockerCmd(c, "images", "hello-world")
c.Assert(images, checker.Contains, "hello-world")
deleteAllImages()
//// load this image will be OK, but after delete this image, there is a residual image with <none> tag occur.
//url = "http://image-tarball.s3.amazonaws.com/test/public/helloworld-no-manifest.tgz"
//output, exitCode, err = dockerCmdWithError("load", "-i", url)
//c.Assert(output, check.Not(checker.Contains), "has been loaded.")
//c.Assert(exitCode, checker.Equals, 0)
//c.Assert(err, checker.IsNil)
//
//images, _ = dockerCmd(c, "images", "hello-world")
//c.Assert(images, checker.Contains, "hello-world")
//
//deleteAllImages()
url = "http://image-tarball.s3.amazonaws.com/test/public/helloworld-no-layer.tgz"
output, exitCode, err = dockerCmdWithError("load", "-i", url)
c.Assert(output, checker.Contains, "no such file or directory")
c.Assert(exitCode, checker.Equals, 1)
c.Assert(err, checker.NotNil)
images, _ = dockerCmd(c, "images", "hello-world")
c.Assert(images, check.Not(checker.Contains), "hello-world")
deleteAllImages()
}
//test normal///////////////////////////////////////////////////////////////////////////
func (s *DockerSuite) TestCliLoadFromUrlValidBasic(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
output, exitCode, err := dockerCmdWithError("load", "-i", publicURL)
c.Assert(output, checker.Contains, "hello-world:latest(sha256:")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)
images, _ := dockerCmd(c, "images", "hello-world")
c.Assert(images, checker.Contains, "hello-world")
}
func (s *DockerSuite) TestCliLoadFromUrlValidCompressedArchiveBasic(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
extAry := [...]string{"tar.gz", "tgz", "tar.bz2", "tar.xz"}
for _, val := range extAry {
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld." + val
output, exitCode, err := dockerCmdWithError("load", "-i", publicURL)
c.Assert(output, checker.Contains, "hello-world:latest(sha256:")
c.Assert(output, checker.Contains, "has been loaded.\n")
c.Assert(exitCode, checker.Equals, 0)
c.Assert(err, checker.IsNil)
time.Sleep(1 * time.Second)
}
}
func (s *DockerSuite) TestCliLoadFromUrlWithQuiet(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
publicURL := "http://image-tarball.s3.amazonaws.com/test/public/helloworld.tar"
out, _, _ := dockerCmdWithStdoutStderr(c, "load", "-q", "-i", publicURL)
c.Assert(out, check.Equals, "")
images, _ := dockerCmd(c, "images", "hello-world")
c.Assert(images, checker.Contains, "hello-world")
}
func (s *DockerSuite) TestCliLoadFromUrlMultipeImageBasic(c *check.C) {
printTestCaseName()
defer printTestDuration(time.Now())
testRequires(c, DaemonIsLinux)
multiImgURL := "http://image-tarball.s3.amazonaws.com/test/public/busybox_alpine.tar"
dockerCmd(c, "load", "-i", multiImgURL)
images, _ := dockerCmd(c, "images", "busybox")
c.Assert(images, checker.Contains, "busybox")
images, _ = dockerCmd(c, "images", "alpine")
c.Assert(images, checker.Contains, "alpine")
}