blob: d03466fd079bd8258fd3b8b13ff1f93f6940e2e1 [file] [log] [blame]
Jamie Hannaford1943b382015-02-12 11:50:02 +01001package databases
2
3import (
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
12func 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
36func 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
68func 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}