-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_test.go
110 lines (84 loc) · 2.46 KB
/
api_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package dknet
import (
"io/ioutil"
"net/http"
"strings"
"testing"
. "gopkg.in/check.v1"
)
type TestDriver struct {
Driver
}
func (t *TestDriver) CreateNetwork(r *CreateNetworkRequest) error {
return nil
}
func (t *TestDriver) DeleteNetwork(r *DeleteNetworkRequest) error {
return nil
}
func (t *TestDriver) CreateEndpoint(r *CreateEndpointRequest) error {
return nil
}
func (t *TestDriver) DeleteEndpoint(r *DeleteEndpointRequest) error {
return nil
}
func (t *TestDriver) Join(r *JoinRequest) (*JoinResponse, error) {
return &JoinResponse{}, nil
}
func (t *TestDriver) Leave(r *LeaveRequest) error {
return nil
}
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type MySuite struct {
h *Handler
}
var _ = Suite(&MySuite{})
func (s *MySuite) SetUpSuite(c *C) {
d := &TestDriver{}
s.h = NewHandler(d)
go s.h.ServeTCP("test", ":8080")
}
func (s *MySuite) TestActivate(c *C) {
response, err := http.Get("http://localhost:8080/Plugin.Activate")
if err != nil {
c.Fatal(err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
c.Assert(string(body), Equals, defaultImplementationManifest+"\n")
}
func (s *MySuite) TestCapabilitiesExchange(c *C) {
response, err := http.Get("http://localhost:8080/NetworkDriver.GetCapabilities")
if err != nil {
c.Fatal(err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
c.Assert(string(body), Equals, defaultScope+"\n")
}
func (s *MySuite) TestCreateNetwork400(c *C) {
response, err := http.Post("http://localhost:8080/NetworkDriver.CreateNetwork",
defaultContentTypeV1_1,
nil)
if err != nil {
c.Fatal(err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
c.Assert(response.StatusCode, Equals, http.StatusBadRequest)
c.Assert(string(body), Equals, `{"Err":"Failed to decode request"}`+"\n")
}
func (s *MySuite) TestCreateNetwork200(c *C) {
request := `{"NetworkID":"d76cfa51738e8a12c5eca71ee69e9d65010a4b48eaad74adab439be7e61b9aaf","Options":{"com.docker.network.generic":{}},"IPv4Data":[{"AddressSpace":"","Gateway":"172.18.0.1/16","Pool":"172.18.0.0/16"}],"IPv6Data":[]}`
response, err := http.Post("http://localhost:8080/NetworkDriver.CreateNetwork",
defaultContentTypeV1_1,
strings.NewReader(request),
)
if err != nil {
c.Fatal(err)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
c.Assert(response.StatusCode, Equals, http.StatusOK)
c.Assert(string(body), Equals, "")
}