Jamie Hannaford | 1943b38 | 2015-02-12 11:50:02 +0100 | [diff] [blame^] | 1 | package databases |
| 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 HandleCreateDBSuccessfully(t *testing.T, instanceID string) { |
| 13 | th.Mux.HandleFunc("/instances/"+instanceID+"/databases", 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 | "databases": [ |
| 19 | { |
| 20 | "character_set": "utf8", |
| 21 | "collate": "utf8_general_ci", |
| 22 | "name": "testingdb" |
| 23 | }, |
| 24 | { |
| 25 | "name": "sampledb" |
| 26 | } |
| 27 | ] |
| 28 | } |
| 29 | `) |
| 30 | |
| 31 | w.Header().Set("Content-Type", "application/json") |
| 32 | w.WriteHeader(http.StatusAccepted) |
| 33 | }) |
| 34 | } |
| 35 | |
| 36 | func HandleListDBsSuccessfully(t *testing.T, instanceID string) { |
| 37 | th.Mux.HandleFunc("/instances/"+instanceID+"/databases", func(w http.ResponseWriter, r *http.Request) { |
| 38 | th.TestMethod(t, r, "GET") |
| 39 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 40 | |
| 41 | w.Header().Set("Content-Type", "application/json") |
| 42 | w.WriteHeader(http.StatusOK) |
| 43 | |
| 44 | fmt.Fprintf(w, ` |
| 45 | { |
| 46 | "databases": [ |
| 47 | { |
| 48 | "name": "anotherexampledb" |
| 49 | }, |
| 50 | { |
| 51 | "name": "exampledb" |
| 52 | }, |
| 53 | { |
| 54 | "name": "nextround" |
| 55 | }, |
| 56 | { |
| 57 | "name": "sampledb" |
| 58 | }, |
| 59 | { |
| 60 | "name": "testingdb" |
| 61 | } |
| 62 | ] |
| 63 | } |
| 64 | `) |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | func HandleDeleteDBSuccessfully(t *testing.T, instanceID, dbName string) { |
| 69 | th.Mux.HandleFunc("/instances/"+instanceID+"/databases/"+dbName, func(w http.ResponseWriter, r *http.Request) { |
| 70 | th.TestMethod(t, r, "DELETE") |
| 71 | th.TestHeader(t, r, "X-Auth-Token", fake.TokenID) |
| 72 | |
| 73 | w.Header().Set("Content-Type", "application/json") |
| 74 | w.WriteHeader(http.StatusAccepted) |
| 75 | }) |
| 76 | } |