forked from AliyunContainerService/pouch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_network_create_test.go
96 lines (82 loc) · 2.35 KB
/
api_network_create_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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package main
import (
"github.com/alibaba/pouch/test/environment"
"github.com/alibaba/pouch/test/request"
"github.com/go-check/check"
)
// APINetworkCreateSuite is the test suite for network create API.
type APINetworkCreateSuite struct{}
func init() {
check.Suite(&APINetworkCreateSuite{})
}
// SetUpTest does common setup in the beginning of each test.
func (suite *APINetworkCreateSuite) SetUpTest(c *check.C) {
SkipIfFalse(c, environment.IsLinux)
}
// TestNetworkCreateOk tests creating network is OK.
func (suite *APINetworkCreateSuite) TestNetworkCreateOk(c *check.C) {
nname := "TestNetworkCreateOk"
obj := map[string]interface{}{
"Name": nname,
"Driver": "bridge",
"IPAM": map[string]interface{}{
"Config": []map[string]interface{}{
{
"Gateway": GateWay,
"Subnet": Subnet,
},
},
},
}
body := request.WithJSONBody(obj)
resp, err := request.Post("/networks/create", body)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 201)
DelNetworkOk(c, nname)
}
// TestNetworkCreateExistentName tests if creating network with an existent name returns error.
func (suite *APINetworkCreateSuite) TestNetworkCreateExistentName(c *check.C) {
nname := "TestNetworkCreateExistentName"
obj := map[string]interface{}{
"Name": nname,
"Driver": "bridge",
"IPAM": map[string]interface{}{
"Config": []map[string]interface{}{
{
"Gateway": GateWay,
"Subnet": Subnet,
},
},
},
}
body := request.WithJSONBody(obj)
resp, err := request.Post("/networks/create", body)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 201)
resp, err = request.Post("/networks/create", body)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 409)
// delete network TestNetworkCreateExistentName
resp, err = request.Delete("/networks/" + nname)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 204)
}
// TestNetworkCreateNilName tests creating network without name returns error.
func (suite *APINetworkCreateSuite) TestNetworkCreateNilName(c *check.C) {
obj := map[string]interface{}{
"Name": nil,
"Driver": "bridge",
"IPAM": map[string]interface{}{
"Config": []map[string]interface{}{
{
"Gateway": GateWay,
"Subnet": Subnet,
},
},
},
}
body := request.WithJSONBody(obj)
resp, err := request.Post("/networks/create", body)
c.Assert(err, check.IsNil)
CheckRespStatus(c, resp, 500)
}