Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame] | 1 | package secgroups |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "net/http" |
| 6 | "testing" |
| 7 | |
| 8 | th "github.com/rackspace/gophercloud/testhelper" |
| 9 | fake "github.com/rackspace/gophercloud/testhelper/client" |
| 10 | ) |
| 11 | |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 12 | const rootPath = "/os-security-groups" |
| 13 | |
Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame] | 14 | func mockListGroupsResponse(t *testing.T) { |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 15 | th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) { |
Jamie Hannaford | 924c09d | 2014-11-19 12:05:38 +0100 | [diff] [blame] | 16 | th.TestMethod(t, r, "GET") |
| 17 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 18 | |
| 19 | w.Header().Add("Content-Type", "application/json") |
| 20 | w.WriteHeader(http.StatusOK) |
| 21 | |
| 22 | fmt.Fprintf(w, ` |
| 23 | { |
| 24 | "security_groups": [ |
| 25 | { |
| 26 | "description": "default", |
| 27 | "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5", |
| 28 | "name": "default", |
| 29 | "rules": [], |
| 30 | "tenant_id": "openstack" |
| 31 | } |
| 32 | ] |
| 33 | } |
| 34 | `) |
| 35 | }) |
| 36 | } |
Jamie Hannaford | a493e64 | 2014-11-19 12:40:30 +0100 | [diff] [blame^] | 37 | |
| 38 | func mockCreateGroupResponse(t *testing.T) { |
| 39 | th.Mux.HandleFunc(rootPath, func(w http.ResponseWriter, r *http.Request) { |
| 40 | th.TestMethod(t, r, "POST") |
| 41 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 42 | |
| 43 | th.TestJSONRequest(t, r, ` |
| 44 | { |
| 45 | "security_group": { |
| 46 | "name": "test", |
| 47 | "description": "something" |
| 48 | } |
| 49 | } |
| 50 | `) |
| 51 | |
| 52 | w.Header().Add("Content-Type", "application/json") |
| 53 | w.WriteHeader(http.StatusOK) |
| 54 | |
| 55 | fmt.Fprintf(w, ` |
| 56 | { |
| 57 | "security_group": { |
| 58 | "description": "something", |
| 59 | "id": "b0e0d7dd-2ca4-49a9-ba82-c44a148b66a5", |
| 60 | "name": "test", |
| 61 | "rules": [], |
| 62 | "tenant_id": "openstack" |
| 63 | } |
| 64 | } |
| 65 | `) |
| 66 | }) |
| 67 | } |