|
| 1 | +// +build fixtures |
| 2 | + |
| 3 | +package networks |
| 4 | + |
| 5 | +import ( |
| 6 | + "fmt" |
| 7 | + "net/http" |
| 8 | + "testing" |
| 9 | + "time" |
| 10 | + |
| 11 | + th "github.com/rackspace/gophercloud/testhelper" |
| 12 | + "github.com/rackspace/gophercloud/testhelper/client" |
| 13 | +) |
| 14 | + |
| 15 | +// ListOutput is a sample response to a List call. |
| 16 | +const ListOutput = ` |
| 17 | +{ |
| 18 | + "networks": [ |
| 19 | + { |
| 20 | + "bridge": "br100", |
| 21 | + "bridge_interface": "eth0", |
| 22 | + "broadcast": "10.0.0.7", |
| 23 | + "cidr": "10.0.0.0/29", |
| 24 | + "cidr_v6": null, |
| 25 | + "created_at": "2011-08-15 06:19:19.387525", |
| 26 | + "deleted": false, |
| 27 | + "deleted_at": null, |
| 28 | + "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, |
| 43 | + "updated_at": "2011-08-16 09:26:13.048257", |
| 44 | + "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, |
| 55 | + "created_at": "2011-08-15 06:19:19.885495", |
| 56 | + "deleted": false, |
| 57 | + "deleted_at": null, |
| 58 | + "dhcp_start": "10.0.0.11", |
| 59 | + "dns1": null, |
| 60 | + "dns2": null, |
| 61 | + "gateway": "10.0.0.9", |
| 62 | + "gateway_v6": null, |
| 63 | + "host": null, |
| 64 | + "id": "20c8acc0-f747-4d71-a389-46d078ebf000", |
| 65 | + "injected": false, |
| 66 | + "label": "mynet_1", |
| 67 | + "multi_host": false, |
| 68 | + "netmask": "255.255.255.248", |
| 69 | + "netmask_v6": null, |
| 70 | + "priority": null, |
| 71 | + "project_id": null, |
| 72 | + "rxtx_base": null, |
| 73 | + "updated_at": null, |
| 74 | + "vlan": 101, |
| 75 | + "vpn_private_address": "10.0.0.10", |
| 76 | + "vpn_public_address": null, |
| 77 | + "vpn_public_port": 1001 |
| 78 | + } |
| 79 | + ] |
| 80 | +} |
| 81 | +` |
| 82 | + |
| 83 | +// GetOutput is a sample response to a Get call. |
| 84 | +const GetOutput = ` |
| 85 | +{ |
| 86 | + "network": { |
| 87 | + "bridge": "br101", |
| 88 | + "bridge_interface": "eth0", |
| 89 | + "broadcast": "10.0.0.15", |
| 90 | + "cidr": "10.0.0.10/29", |
| 91 | + "cidr_v6": null, |
| 92 | + "created_at": "2011-08-15 06:19:19.885495", |
| 93 | + "deleted": false, |
| 94 | + "deleted_at": null, |
| 95 | + "dhcp_start": "10.0.0.11", |
| 96 | + "dns1": null, |
| 97 | + "dns2": null, |
| 98 | + "gateway": "10.0.0.9", |
| 99 | + "gateway_v6": null, |
| 100 | + "host": null, |
| 101 | + "id": "20c8acc0-f747-4d71-a389-46d078ebf000", |
| 102 | + "injected": false, |
| 103 | + "label": "mynet_1", |
| 104 | + "multi_host": false, |
| 105 | + "netmask": "255.255.255.248", |
| 106 | + "netmask_v6": null, |
| 107 | + "priority": null, |
| 108 | + "project_id": null, |
| 109 | + "rxtx_base": null, |
| 110 | + "updated_at": null, |
| 111 | + "vlan": 101, |
| 112 | + "vpn_private_address": "10.0.0.10", |
| 113 | + "vpn_public_address": null, |
| 114 | + "vpn_public_port": 1001 |
| 115 | + } |
| 116 | +} |
| 117 | +` |
| 118 | + |
| 119 | +// FirstNetwork is the first result in ListOutput. |
| 120 | +var nilTime time.Time |
| 121 | +var FirstNetwork = Network{ |
| 122 | + Bridge: "br100", |
| 123 | + BridgeInterface: "eth0", |
| 124 | + Broadcast: "10.0.0.7", |
| 125 | + CIDR: "10.0.0.0/29", |
| 126 | + CIDRv6: "", |
| 127 | + CreatedAt: time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC), |
| 128 | + Deleted: false, |
| 129 | + DeletedAt: nilTime, |
| 130 | + DHCPStart: "10.0.0.3", |
| 131 | + DNS1: "", |
| 132 | + DNS2: "", |
| 133 | + Gateway: "10.0.0.1", |
| 134 | + Gatewayv6: "", |
| 135 | + Host: "nsokolov-desktop", |
| 136 | + ID: "20c8acc0-f747-4d71-a389-46d078ebf047", |
| 137 | + Injected: false, |
| 138 | + Label: "mynet_0", |
| 139 | + MultiHost: false, |
| 140 | + Netmask: "255.255.255.248", |
| 141 | + Netmaskv6: "", |
| 142 | + Priority: 0, |
| 143 | + ProjectID: "1234", |
| 144 | + RXTXBase: 0, |
| 145 | + UpdatedAt: time.Date(2011, 8, 16, 9, 26, 13, 48257000, time.UTC), |
| 146 | + VLAN: 100, |
| 147 | + VPNPrivateAddress: "10.0.0.2", |
| 148 | + VPNPublicAddress: "127.0.0.1", |
| 149 | + VPNPublicPort: 1000, |
| 150 | +} |
| 151 | + |
| 152 | +// SecondNetwork is the second result in ListOutput. |
| 153 | +var SecondNetwork = Network{ |
| 154 | + Bridge: "br101", |
| 155 | + BridgeInterface: "eth0", |
| 156 | + Broadcast: "10.0.0.15", |
| 157 | + CIDR: "10.0.0.10/29", |
| 158 | + CIDRv6: "", |
| 159 | + CreatedAt: time.Date(2011, 8, 15, 6, 19, 19, 885495000, time.UTC), |
| 160 | + Deleted: false, |
| 161 | + DeletedAt: nilTime, |
| 162 | + DHCPStart: "10.0.0.11", |
| 163 | + DNS1: "", |
| 164 | + DNS2: "", |
| 165 | + Gateway: "10.0.0.9", |
| 166 | + Gatewayv6: "", |
| 167 | + Host: "", |
| 168 | + ID: "20c8acc0-f747-4d71-a389-46d078ebf000", |
| 169 | + Injected: false, |
| 170 | + Label: "mynet_1", |
| 171 | + MultiHost: false, |
| 172 | + Netmask: "255.255.255.248", |
| 173 | + Netmaskv6: "", |
| 174 | + Priority: 0, |
| 175 | + ProjectID: "", |
| 176 | + RXTXBase: 0, |
| 177 | + UpdatedAt: nilTime, |
| 178 | + VLAN: 101, |
| 179 | + VPNPrivateAddress: "10.0.0.10", |
| 180 | + VPNPublicAddress: "", |
| 181 | + VPNPublicPort: 1001, |
| 182 | +} |
| 183 | + |
| 184 | +// ExpectedNetworkSlice is the slice of results that should be parsed |
| 185 | +// from ListOutput, in the expected order. |
| 186 | +var ExpectedNetworkSlice = []Network{FirstNetwork, SecondNetwork} |
| 187 | + |
| 188 | +// HandleListSuccessfully configures the test server to respond to a List request. |
| 189 | +func HandleListSuccessfully(t *testing.T) { |
| 190 | + th.Mux.HandleFunc("/os-networks", func(w http.ResponseWriter, r *http.Request) { |
| 191 | + th.TestMethod(t, r, "GET") |
| 192 | + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 193 | + |
| 194 | + w.Header().Add("Content-Type", "application/json") |
| 195 | + fmt.Fprintf(w, ListOutput) |
| 196 | + }) |
| 197 | +} |
| 198 | + |
| 199 | +// HandleGetSuccessfully configures the test server to respond to a Get request |
| 200 | +// for an existing network. |
| 201 | +func HandleGetSuccessfully(t *testing.T) { |
| 202 | + th.Mux.HandleFunc("/os-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) { |
| 203 | + th.TestMethod(t, r, "GET") |
| 204 | + th.TestHeader(t, r, "X-Auth-Token", client.TokenID) |
| 205 | + |
| 206 | + w.Header().Add("Content-Type", "application/json") |
| 207 | + fmt.Fprintf(w, GetOutput) |
| 208 | + }) |
| 209 | +} |
0 commit comments