Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 1 | // +build fixtures |
| 2 | |
| 3 | package networks |
| 4 | |
| 5 | import ( |
| 6 | "fmt" |
| 7 | "net/http" |
| 8 | "testing" |
| 9 | "time" |
| 10 | |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 11 | "github.com/gophercloud/gophercloud" |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 12 | th "github.com/gophercloud/gophercloud/testhelper" |
| 13 | "github.com/gophercloud/gophercloud/testhelper/client" |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 14 | ) |
| 15 | |
| 16 | // ListOutput is a sample response to a List call. |
| 17 | const 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 Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 26 | "created_at": "2011-08-15T06:19:19.387525", |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 27 | "deleted": false, |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 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, |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 43 | "updated_at": "2011-08-16T09:26:13.048257", |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 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, |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 55 | "created_at": "2011-08-15T06:19:19.387525", |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 56 | "deleted": false, |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 57 | "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 Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 72 | "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. |
| 82 | const 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 Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 90 | "created_at": "2011-08-15T06:19:19.387525", |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 91 | "deleted": false, |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 92 | "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 Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 107 | "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. |
| 116 | var nilTime time.Time |
| 117 | var FirstNetwork = Network{ |
| 118 | Bridge: "br100", |
| 119 | BridgeInterface: "eth0", |
| 120 | Broadcast: "10.0.0.7", |
| 121 | CIDR: "10.0.0.0/29", |
| 122 | CIDRv6: "", |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 123 | CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 124 | Deleted: false, |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 125 | DeletedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 126 | 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 Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 141 | UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 16, 9, 26, 13, 48257000, time.UTC)), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 142 | 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. |
| 149 | var SecondNetwork = Network{ |
| 150 | Bridge: "br101", |
| 151 | BridgeInterface: "eth0", |
| 152 | Broadcast: "10.0.0.15", |
| 153 | CIDR: "10.0.0.10/29", |
| 154 | CIDRv6: "", |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 155 | CreatedAt: gophercloud.JSONRFC3339MilliNoZ(time.Date(2011, 8, 15, 6, 19, 19, 387525000, time.UTC)), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 156 | Deleted: false, |
Jon Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 157 | DeletedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 158 | 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 Perritt | 1239521 | 2016-02-24 10:41:17 -0600 | [diff] [blame] | 173 | UpdatedAt: gophercloud.JSONRFC3339MilliNoZ(nilTime), |
Joe Topjian | 99a0613 | 2015-02-22 05:06:25 +0000 | [diff] [blame] | 174 | 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. |
| 182 | var ExpectedNetworkSlice = []Network{FirstNetwork, SecondNetwork} |
| 183 | |
| 184 | // HandleListSuccessfully configures the test server to respond to a List request. |
| 185 | func 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. |
| 197 | func 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 | } |