forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_volume_list_test.go
59 lines (48 loc) · 1.61 KB
/
api_volume_list_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
package main
import (
"github.com/alibaba/pouch/apis/types"
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APIVolumeListSuite is the test suite for volume inspect API.
type APIVolumeListSuite struct{}
func init() {
check.Suite(&APIVolumeListSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APIVolumeListSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
}
// TestVolumeListOk tests if list volumes is OK.
func (suite *APIVolumeListSuite) TestVolumeListOk(c *check.C) {
// Create a volume with the name "TestVolume1".
CreateVolumeOK(c, "TestVolume1", "local", nil)
defer RemoveVolumeOK(c, "TestVolume1")
// Create a volume with the name "TestVolume2".
CreateVolumeOK(c, "TestVolume2", "local", nil)
defer RemoveVolumeOK(c, "TestVolume2")
// Create a volume with the name "TestVolume3".
options := map[string]string{"mountpoint": "/data/TestVolume3"}
CreateVolumeOK(c, "TestVolume3", "local", options)
defer RemoveVolumeOK(c, "TestVolume3")
// Test volume list feature.
path := "/volumes"
resp, err := request.Get(path)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 200)
// Check list result.
volumeListResp := &types.VolumeListResp{}
err = request.DecodeBody(volumeListResp, resp.Body)
c.Assert(err, check.IsNil)
// Check response having the pre-created two volumes.
found := 0
for _, volume := range volumeListResp.Volumes {
if volume.Name == "TestVolume1" ||
volume.Name == "TestVolume2" ||
volume.Name == "TestVolume3" {
found++
}
}
c.Assert(found, check.Equals, 3)
}