| Joe Topjian | c21202d | 2015-02-27 21:32:58 +0000 | [diff] [blame^] | 1 | // +build fixtures | 
|  | 2 |  | 
|  | 3 | package tenantnetworks | 
|  | 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 | "cidr": "10.0.0.0/29", | 
|  | 21 | "id": "20c8acc0-f747-4d71-a389-46d078ebf047", | 
|  | 22 | "label": "mynet_0" | 
|  | 23 | }, | 
|  | 24 | { | 
|  | 25 | "cidr": "10.0.0.10/29", | 
|  | 26 | "id": "20c8acc0-f747-4d71-a389-46d078ebf000", | 
|  | 27 | "label": "mynet_1" | 
|  | 28 | } | 
|  | 29 | ] | 
|  | 30 | } | 
|  | 31 | ` | 
|  | 32 |  | 
|  | 33 | // GetOutput is a sample response to a Get call. | 
|  | 34 | const GetOutput = ` | 
|  | 35 | { | 
|  | 36 | "network": { | 
|  | 37 | "cidr": "10.0.0.10/29", | 
|  | 38 | "id": "20c8acc0-f747-4d71-a389-46d078ebf000", | 
|  | 39 | "label": "mynet_1" | 
|  | 40 | } | 
|  | 41 | } | 
|  | 42 | ` | 
|  | 43 |  | 
|  | 44 | // FirstNetwork is the first result in ListOutput. | 
|  | 45 | var nilTime time.Time | 
|  | 46 | var FirstNetwork = Network{ | 
|  | 47 | CIDR: "10.0.0.0/29", | 
|  | 48 | ID:   "20c8acc0-f747-4d71-a389-46d078ebf047", | 
|  | 49 | Name: "mynet_0", | 
|  | 50 | } | 
|  | 51 |  | 
|  | 52 | // SecondNetwork is the second result in ListOutput. | 
|  | 53 | var SecondNetwork = Network{ | 
|  | 54 | CIDR: "10.0.0.10/29", | 
|  | 55 | ID:   "20c8acc0-f747-4d71-a389-46d078ebf000", | 
|  | 56 | Name: "mynet_1", | 
|  | 57 | } | 
|  | 58 |  | 
|  | 59 | // ExpectedNetworkSlice is the slice of results that should be parsed | 
|  | 60 | // from ListOutput, in the expected order. | 
|  | 61 | var ExpectedNetworkSlice = []Network{FirstNetwork, SecondNetwork} | 
|  | 62 |  | 
|  | 63 | // HandleListSuccessfully configures the test server to respond to a List request. | 
|  | 64 | func HandleListSuccessfully(t *testing.T) { | 
|  | 65 | th.Mux.HandleFunc("/os-tenant-networks", func(w http.ResponseWriter, r *http.Request) { | 
|  | 66 | th.TestMethod(t, r, "GET") | 
|  | 67 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) | 
|  | 68 |  | 
|  | 69 | w.Header().Add("Content-Type", "application/json") | 
|  | 70 | fmt.Fprintf(w, ListOutput) | 
|  | 71 | }) | 
|  | 72 | } | 
|  | 73 |  | 
|  | 74 | // HandleGetSuccessfully configures the test server to respond to a Get request | 
|  | 75 | // for an existing network. | 
|  | 76 | func HandleGetSuccessfully(t *testing.T) { | 
|  | 77 | th.Mux.HandleFunc("/os-tenant-networks/20c8acc0-f747-4d71-a389-46d078ebf000", func(w http.ResponseWriter, r *http.Request) { | 
|  | 78 | th.TestMethod(t, r, "GET") | 
|  | 79 | th.TestHeader(t, r, "X-Auth-Token", client.TokenID) | 
|  | 80 |  | 
|  | 81 | w.Header().Add("Content-Type", "application/json") | 
|  | 82 | fmt.Fprintf(w, GetOutput) | 
|  | 83 | }) | 
|  | 84 | } |