forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_container_delete_test.go
80 lines (60 loc) · 2.22 KB
/
api_container_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
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
package main
import (
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APIContainerDeleteSuite is the test suite for container delete API.
type APIContainerDeleteSuite struct{}
func init() {
check.Suite(&APIContainerDeleteSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerDeleteSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
PullImage(c, busyboxImage)
}
// TestDeleteNonExisting tests deleting a non-existing container return error.
func (suite *APIContainerDeleteSuite) TestDeleteNonExisting(c *check.C) {
cname := "TestDeleteNonExisting"
resp, err := request.Delete("/containers/" + cname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 404)
}
// TestDeleteRunningCon test deleting running container, should return 500.
func (suite *APIContainerDeleteSuite) TestDeleteRunningCon(c *check.C) {
cname := "TestDeleteRunningContainer"
CreateBusyboxContainerOk(c, cname)
StartContainerOk(c, cname)
resp, err := request.Delete("/containers/" + cname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
}
// TestDeletePausedCon test deleting paused container, should return 500.
func (suite *APIContainerDeleteSuite) TestDeletePausedCon(c *check.C) {
cname := "TestDeletePausedContainer"
CreateBusyboxContainerOk(c, cname)
StartContainerOk(c, cname)
PauseContainerOk(c, cname)
resp, err := request.Delete("/containers/" + cname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
}
// TestDeleteStoppedCon test deleting stopped container return 204.
func (suite *APIContainerDeleteSuite) TestDeleteStoppedCon(c *check.C) {
cname := "TestDeleteStoppedCon"
CreateBusyboxContainerOk(c, cname)
StartContainerOk(c, cname)
StopContainerOk(c, cname)
resp, err := request.Delete("/containers/" + cname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}
// TestDeleteCreatedCon test deleting created container return 204.
func (suite *APIContainerDeleteSuite) TestDeleteCreatedCon(c *check.C) {
cname := "TestDeleteCreatedCon"
CreateBusyboxContainerOk(c, cname)
resp, err := request.Delete("/containers/" + cname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}