blob: ffa42827098ce03c7f75e32317f1eddec6456e5b [file] [log] [blame]
Joe Topjian99a06132015-02-22 05:06:25 +00001// +build fixtures
2
3package networks
4
5import (
6 "fmt"
7 "net/http"
8 "testing"
9 "time"
10
Jon Perritt12395212016-02-24 10:41:17 -060011 "github.com/gophercloud/gophercloud"
Jon Perritt27249f42016-02-18 10:35:59 -060012 th "github.com/gophercloud/gophercloud/testhelper"
13 "github.com/gophercloud/gophercloud/testhelper/client"
Joe Topjian99a06132015-02-22 05:06:25 +000014)
15
16// ListOutput is a sample response to a List call.
17const ListOutput = `
18{
19 "networks": [
20 {
21 "bridge": "br100",
22 "bridge_interface": "eth0",
23 "broadcast": "10.0.0.7",
24 "cidr": "10.0.0.0/29",
25 "cidr_v6": null,
Jon Perritt12395212016-02-24 10:41:17 -060026 "created_at": "2011-08-15T06:19:19.387525",
Joe Topjian99a06132015-02-22 05:06:25 +000027 "deleted": false,
Joe Topjian99a06132015-02-22 05:06:25 +000028 "dhcp_start": "10.0.0.3",
29 "dns1": null,
30 "dns2": null,
31 "gateway": "10.0.0.1",
32 "gateway_v6": null,
33 "host": "nsokolov-desktop",
34 "id": "20c8acc0-f747-4d71-a389-46d078ebf047",
35 "injected": false,
36 "label": "mynet_0",
37 "multi_host": false,
38 "netmask": "255.255.255.248",
39 "netmask_v6": null,
40 "priority": null,
41 "project_id": "1234",
42 "rxtx_base": null,
Jon Perritt12395212016-02-24 10:41:17 -060043 "updated_at": "2011-08-16T09:26:13.048257",
Joe Topjian99a06132015-02-22 05:06:25 +000044 "vlan": 100,
45 "vpn_private_address": "10.0.0.2",
46 "vpn_public_address": "127.0.0.1",
47 "vpn_public_port": 1000
48 },
49 {
50 "bridge": "br101",
51 "bridge_interface": "eth0",
52 "broadcast": "10.0.0.15",
53 "cidr": "10.0.0.10/29",
54 "cidr_v6": null,
Jon Perritt12395212016-02-24 10:41:17 -060055 "created_at": "2011-08-15T06:19:19.387525",
Joe Topjian99a06132015-02-22 05:06:25 +000056 "deleted": false,
Joe Topjian99a06132015-02-22 05:06:25 +000057 "dhcp_start": "10.0.0.11",
58 "dns1": null,
59 "dns2": null,
60 "gateway": "10.0.0.9",
61 "gateway_v6": null,
62 "host": null,
63 "id": "20c8acc0-f747-4d71-a389-46d078ebf000",
64 "injected": false,
65 "label": "mynet_1",
66 "multi_host": false,
67 "netmask": "255.255.255.248",
68 "netmask_v6": null,
69 "priority": null,
70 "project_id": null,
71 "rxtx_base": null,
Joe Topjian99a06132015-02-22 05:06:25 +000072 "vlan": 101,
73 "vpn_private_address": "10.0.0.10",
74 "vpn_public_address": null,
75 "vpn_public_port": 1001
76 }
77 ]
78}
79`
80
81// GetOutput is a sample response to a Get call.
82const GetOutput = `
83{
84 "network": {
85 "bridge": "br101",
86 "bridge_interface": "eth0",
87 "broadcast": "10.0.0.15",
88 "cidr": "10.0.0.10/29",
89 "cidr_v6": null,
Jon Perritt12395212016-02-24 10:41:17 -060090 "created_at": "2011-08-15T06:19:19.387525",
Joe Topjian99a06132015-02-22 05:06:25 +000091 "deleted": false,
Joe Topjian99a06132015-02-22 05:06:25 +000092 "dhcp_start": "10.0.0.11",
93 "dns1": null,
94 "dns2": null,
95 "gateway": "10.0.0.9",
96 "gateway_v6": null,
97 "host": null,
98 "id": "20c8acc0-f747-4d71-a389-46d078ebf000",
99 "injected": false,
100 "label": "mynet_1",
101 "multi_host": false,
102 "netmask": "255.255.255.248",
103 "netmask_v6": null,
104 "priority": null,
105 "project_id": null,
106 "rxtx_base": null,
Joe Topjian99a06132015-02-22 05:06:25 +0000107 "vlan": 101,
108 "vpn_private_address": "10.0.0.10",
109 "vpn_public_address": null,
110 "vpn_public_port": 1001
111 }
112}
113`
114
115// FirstNetwork is the first result in ListOutput.
116var nilTime time.Time
117var FirstNetwork = Network{
118 Bridge: "br100",
119 BridgeInterface: "eth0",
120 Broadcast: "10.0.0.7",
121 CIDR: "10.0.0.0/29",
122 CIDRv6: "",
Jon Perritt12395212016-02-24 10:41:17 -0600123 CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)),
Joe Topjian99a06132015-02-22 05:06:25 +0000124 Deleted: false,
Jon Perritt12395212016-02-24 10:41:17 -0600125 DeletedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
Joe Topjian99a06132015-02-22 05:06:25 +0000126 DHCPStart: "10.0.0.3",
127 DNS1: "",
128 DNS2: "",
129 Gateway: "10.0.0.1",
130 Gatewayv6: "",
131 Host: "nsokolov-desktop",
132 ID: "20c8acc0-f747-4d71-a389-46d078ebf047",
133 Injected: false,
134 Label: "mynet_0",
135 MultiHost: false,
136 Netmask: "255.255.255.248",
137 Netmaskv6: "",
138 Priority: 0,
139 ProjectID: "1234",
140 RXTXBase: 0,
Jon Perritt12395212016-02-24 10:41:17 -0600141 UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 16, 9, 26, 13, 48257000, time.UTC)),
Joe Topjian99a06132015-02-22 05:06:25 +0000142 VLAN: 100,
143 VPNPrivateAddress: "10.0.0.2",
144 VPNPublicAddress: "127.0.0.1",
145 VPNPublicPort: 1000,
146}
147
148// SecondNetwork is the second result in ListOutput.
149var SecondNetwork = Network{
150 Bridge: "br101",
151 BridgeInterface: "eth0",
152 Broadcast: "10.0.0.15",
153 CIDR: "10.0.0.10/29",
154 CIDRv6: "",
Jon Perritt12395212016-02-24 10:41:17 -0600155 CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)),
Joe Topjian99a06132015-02-22 05:06:25 +0000156 Deleted: false,
Jon Perritt12395212016-02-24 10:41:17 -0600157 DeletedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
Joe Topjian99a06132015-02-22 05:06:25 +0000158 DHCPStart: "10.0.0.11",
159 DNS1: "",
160 DNS2: "",
161 Gateway: "10.0.0.9",
162 Gatewayv6: "",
163 Host: "",
164 ID: "20c8acc0-f747-4d71-a389-46d078ebf000",
165 Injected: false,
166 Label: "mynet_1",
167 MultiHost: false,
168 Netmask: "255.255.255.248",
169 Netmaskv6: "",
170 Priority: 0,
171 ProjectID: "",
172 RXTXBase: 0,
Jon Perritt12395212016-02-24 10:41:17 -0600173 UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime),
Joe Topjian99a06132015-02-22 05:06:25 +0000174 VLAN: 101,
175 VPNPrivateAddress: "10.0.0.10",
176 VPNPublicAddress: "",
177 VPNPublicPort: 1001,
178}
179
180// ExpectedNetworkSlice is the slice of results that should be parsed
181// from ListOutput, in the expected order.
182var ExpectedNetworkSlice = []Network{FirstNetwork, SecondNetwork}
183
184// HandleListSuccessfully configures the test server to respond to a List request.
185func HandleListSuccessfully(t *testing.T) {
186 th.Mux.HandleFunc("/os-networks", func(w http.ResponseWriter, r *http.Request) {
187 th.TestMethod(t, r, "GET")
188 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
189
190 w.Header().Add("Content-Type", "application/json")
191 fmt.Fprintf(w, ListOutput)
192 })
193}
194
195// HandleGetSuccessfully configures the test server to respond to a Get request
196// for an existing network.
197func HandleGetSuccessfully(t *testing.T) {
198 th.Mux.HandleFunc("/os-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) {
199 th.TestMethod(t, r, "GET")
200 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
201
202 w.Header().Add("Content-Type", "application/json")
203 fmt.Fprintf(w, GetOutput)
204 })
205}