forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_image_delete_test.go
52 lines (42 loc) · 1.51 KB
/
api_image_delete_test.go
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
package main
import (
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APIImageDeleteSuite is the test suite for image delete API.
type APIImageDeleteSuite struct{}
func init() {
check.Suite(&APIImageDeleteSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APIImageDeleteSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
}
// TestDeleteNonExisting tests deleting a non-existing image return error.
func (suite *APIImageDeleteSuite) TestDeleteNonExisting(c *check.C) {
img := "TestDeleteNonExisting"
resp, err := request.Delete("/images/" + img)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 404)
}
// TestDeleteImageOk tests deleting an image is ok.
func (suite *APIImageDeleteSuite) TestDeleteImageOk(c *check.C) {
PullImage(c, helloworldImage)
resp, err := request.Delete("/images/" + helloworldImage)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
resp, err = request.Get("/images/" + helloworldImage + "/json")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 404)
}
// TestDeleteUsingImage tests deleting an image in use by running container will fail.
func (suite *APIImageDeleteSuite) TestDeleteUsingImage(c *check.C) {
cname := "TestDeleteUsingImage"
CreateBusyboxContainerOk(c, cname)
defer DelContainerForceMultyTime(c, cname)
StartContainerOk(c, cname)
resp, err := request.Delete("/images/" + busyboxImage)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
}