| ehdou | 10f1f85 | 2016-10-14 20:58:23 +0300 | [diff] [blame] | 1 | package testing | 
|  | 2 |  | 
|  | 3 | import ( | 
|  | 4 | "fmt" | 
|  | 5 | "net/http" | 
|  | 6 | "testing" | 
|  | 7 |  | 
|  | 8 | th "github.com/gophercloud/gophercloud/testhelper" | 
|  | 9 | fake "github.com/gophercloud/gophercloud/testhelper/client" | 
|  | 10 | ) | 
|  | 11 |  | 
|  | 12 | func createReq(name, description, network, subnetwork string) string { | 
|  | 13 | return fmt.Sprintf(`{ | 
|  | 14 | "share_network": { | 
|  | 15 | "name": "%s", | 
|  | 16 | "description": "%s", | 
|  | 17 | "neutron_net_id": "%s", | 
|  | 18 | "neutron_subnet_id": "%s" | 
|  | 19 | } | 
|  | 20 | }`, name, description, network, subnetwork) | 
|  | 21 | } | 
|  | 22 |  | 
|  | 23 | func createResp(name, description, network, subnetwork string) string { | 
|  | 24 | return fmt.Sprintf(` | 
|  | 25 | { | 
|  | 26 | "share_network": { | 
|  | 27 | "name": "%s", | 
|  | 28 | "description": "%s", | 
|  | 29 | "segmentation_id": null, | 
|  | 30 | "created_at": "2015-09-07T14:37:00.583656", | 
|  | 31 | "updated_at": null, | 
|  | 32 | "id": "77eb3421-4549-4789-ac39-0d5185d68c29", | 
|  | 33 | "neutron_net_id": "%s", | 
|  | 34 | "neutron_subnet_id": "%s", | 
|  | 35 | "ip_version": null, | 
|  | 36 | "nova_net_id": null, | 
|  | 37 | "cidr": null, | 
|  | 38 | "project_id": "e10a683c20da41248cfd5e1ab3d88c62", | 
|  | 39 | "network_type": null | 
|  | 40 | } | 
|  | 41 | }`, name, description, network, subnetwork) | 
|  | 42 | } | 
|  | 43 |  | 
|  | 44 | func MockCreateResponse(t *testing.T) { | 
|  | 45 | th.Mux.HandleFunc("/share-networks", func(w http.ResponseWriter, r *http.Request) { | 
|  | 46 | th.TestMethod(t, r, "POST") | 
|  | 47 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 48 | th.TestHeader(t, r, "Content-Type", "application/json") | 
|  | 49 | th.TestHeader(t, r, "Accept", "application/json") | 
|  | 50 | th.TestJSONRequest(t, r, createReq("my_network", | 
|  | 51 | "This is my share network", | 
|  | 52 | "998b42ee-2cee-4d36-8b95-67b5ca1f2109", | 
|  | 53 | "53482b62-2c84-4a53-b6ab-30d9d9800d06")) | 
|  | 54 |  | 
|  | 55 | w.Header().Add("Content-Type", "application/json") | 
|  | 56 | w.WriteHeader(http.StatusAccepted) | 
|  | 57 |  | 
|  | 58 | fmt.Fprintf(w, createResp("my_network", | 
|  | 59 | "This is my share network", | 
|  | 60 | "998b42ee-2cee-4d36-8b95-67b5ca1f2109", | 
|  | 61 | "53482b62-2c84-4a53-b6ab-30d9d9800d06")) | 
|  | 62 | }) | 
|  | 63 | } | 
| ehdou | 5368725 | 2016-10-14 22:10:13 +0300 | [diff] [blame] | 64 |  | 
|  | 65 | func MockDeleteResponse(t *testing.T) { | 
|  | 66 | th.Mux.HandleFunc("/share-networks/fa158a3d-6d9f-4187-9ca5-abbb82646eb2", func(w http.ResponseWriter, r *http.Request) { | 
|  | 67 | th.TestMethod(t, r, "DELETE") | 
|  | 68 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) | 
|  | 69 | w.WriteHeader(http.StatusAccepted) | 
|  | 70 | }) | 
|  | 71 | } |