forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_container_stop_test.go
80 lines (60 loc) · 2.09 KB
/
api_container_stop_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 (
"net/url"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APIContainerStopSuite is the test suite for container stop API.
type APIContainerStopSuite struct{}
func init() {
check.Suite(&APIContainerStopSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerStopSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
PullImage(c, busyboxImage)
}
// TestStopOk tests a running container could be stopped.
func (suite *APIContainerStopSuite) TestStopOk(c *check.C) {
cname := "TestStopOk"
CreateBusyboxContainerOk(c, cname)
defer DelContainerForceMultyTime(c, cname)
StartContainerOk(c, cname)
StopContainerOk(c, cname)
}
// TestNonExistingContainer tests stop a non-existing container return 404.
func (suite *APIContainerStopSuite) TestNonExistingContainer(c *check.C) {
cname := "TestNonExistingContainer"
resp, err := request.Post("/containers/" + cname + "/stop")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 404)
}
// TestStopWait tests waiting before stopping container.
func (suite *APIContainerStopSuite) TestStopWait(c *check.C) {
cname := "TestStopOk"
CreateBusyboxContainerOk(c, cname)
defer DelContainerForceMultyTime(c, cname)
StartContainerOk(c, cname)
q := url.Values{}
q.Add("t", "1")
query := request.WithQuery(q)
resp, err := request.Post("/containers/"+cname+"/stop", query)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}
// TestInvalidParam tests using invalid parameter return.
func (suite *APIContainerStopSuite) TestInvalidParam(c *check.C) {
// TODO: missing case
helpwantedForMissingCase(c, "container api stop bad request case")
}
// TestStopPausedContainer tests stop a paused container.
func (suite *APIContainerStopSuite) TestStopPausedContainer(c *check.C) {
cname := "TestStopPausedContainer"
CreateBusyboxContainerOk(c, cname)
defer DelContainerForceMultyTime(c, cname)
StartContainerOk(c, cname)
PauseContainerOk(c, cname)
StopContainerOk(c, cname)
CheckContainerStatus(c, cname, "stopped")
}