Jamie Hannaford | af4570f | 2015-02-12 13:33:25 +0100 | [diff] [blame] | 1 | package users |
| 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 | |
| 12 | func HandleCreateUserSuccessfully(t *testing.T, instanceID string) { |
| 13 | th.Mux.HandleFunc("/instances/"+instanceID+"/users", func(w http.ResponseWriter, r *http.Request) { |
| 14 | th.TestMethod(t, r, "POST") |
| 15 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 16 | th.TestJSONRequest(t, r, ` |
| 17 | { |
| 18 | "users": [ |
| 19 | { |
| 20 | "databases": [ |
| 21 | { |
| 22 | "name": "databaseA" |
| 23 | } |
| 24 | ], |
| 25 | "name": "dbuser3", |
| 26 | "password": "secretsecret" |
| 27 | }, |
| 28 | { |
| 29 | "databases": [ |
| 30 | { |
| 31 | "name": "databaseB" |
| 32 | }, |
| 33 | { |
| 34 | "name": "databaseC" |
| 35 | } |
| 36 | ], |
| 37 | "name": "dbuser4", |
| 38 | "password": "secretsecret" |
| 39 | } |
| 40 | ] |
| 41 | } |
| 42 | `) |
| 43 | |
| 44 | w.Header().Set("Content-Type", "application/json") |
| 45 | w.WriteHeader(http.StatusAccepted) |
| 46 | }) |
| 47 | } |
| 48 | |
| 49 | func HandleListUsersSuccessfully(t *testing.T, instanceID string) { |
| 50 | th.Mux.HandleFunc("/instances/"+instanceID+"/users", func(w http.ResponseWriter, r *http.Request) { |
| 51 | th.TestMethod(t, r, "GET") |
| 52 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 53 | |
| 54 | w.Header().Set("Content-Type", "application/json") |
| 55 | w.WriteHeader(http.StatusOK) |
| 56 | |
| 57 | fmt.Fprintf(w, ` |
| 58 | { |
| 59 | "users": [ |
| 60 | { |
| 61 | "databases": [ |
| 62 | { |
| 63 | "name": "databaseA" |
| 64 | } |
| 65 | ], |
| 66 | "name": "dbuser3" |
| 67 | }, |
| 68 | { |
| 69 | "databases": [ |
| 70 | { |
| 71 | "name": "databaseB" |
| 72 | }, |
| 73 | { |
| 74 | "name": "databaseC" |
| 75 | } |
| 76 | ], |
| 77 | "name": "dbuser4" |
| 78 | } |
| 79 | ] |
| 80 | } |
| 81 | `) |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | func HandleDeleteUserSuccessfully(t *testing.T, instanceID, dbName string) { |
| 86 | th.Mux.HandleFunc("/instances/"+instanceID+"/users/"+dbName, func(w http.ResponseWriter, r *http.Request) { |
| 87 | th.TestMethod(t, r, "DELETE") |
| 88 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 89 | w.WriteHeader(http.StatusAccepted) |
| 90 | }) |
| 91 | } |