forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_container_inspect_test.go
82 lines (63 loc) · 2.47 KB
/
api_container_inspect_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
81
82
package main
import (
"time"
"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APIContainerInspectSuite is the test suite for container inspect API.
type APIContainerInspectSuite struct{}
func init() {
check.Suite(&APIContainerInspectSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APIContainerInspectSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
PullImage(c, busyboxImage)
PullImage(c, busyboxImage125)
}
// TestInspectNoSuchContainer tests inspecting a container that doesn't exits return error.
func (suite *APIContainerInspectSuite) TestInspectNoSuchContainer(c *check.C) {
resp, err := request.Get("/containers/nosuchcontainerxxx/json")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 404)
}
// TestInspectOk tests inspecting an existing container is OK.
func (suite *APIContainerInspectSuite) TestInpectOk(c *check.C) {
cname := "TestInpectOk"
resp, err := CreateBusybox125Container(cname, "top")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 201)
defer DelContainerForceMultyTime(c, cname)
resp, err = request.Get("/containers/" + cname + "/json")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 200)
got := types.ContainerJSON{}
err = request.DecodeBody(&got, resp.Body)
c.Assert(err, check.IsNil)
// TODO: missing case
//
// add more field checker
c.Assert(got.Name, check.Equals, cname)
c.Assert(got.Image, check.Equals, busyboxImage125ID)
c.Assert(got.Config.Image, check.Equals, busyboxImage125)
c.Assert(got.Created, check.NotNil)
// StartedAt time should be 0001-01-01T00:00:00Z for a non-started container
c.Assert(got.State.StartedAt, check.Equals, time.Time{}.UTC().Format(time.RFC3339Nano))
// FinishAt time should be 0001-01-01T00:00:00Z for a non-stopped container
c.Assert(got.State.FinishedAt, check.Equals, time.Time{}.UTC().Format(time.RFC3339Nano))
}
// TestInspectPid tests the response of inspect has process pid.
func (suite *APIContainerInspectSuite) TestInspectPid(c *check.C) {
cname := "TestInspectPid"
CreateBusyboxContainerOk(c, cname)
defer DelContainerForceMultyTime(c, cname)
StartContainerOk(c, cname)
resp, err := request.Get("/containers/" + cname + "/json")
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 200)
got := types.ContainerJSON{}
c.Assert(request.DecodeBody(&got, resp.Body), check.IsNil)
c.Assert(got.State.Pid, check.NotNil)
}