blob: 7fde6e5c22dd9554a7fd4460205ff18b9c325cfb [file] [log] [blame]
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +01001package instances
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 HandleCreateInstanceSuccessfully(t *testing.T) {
13 th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
14 th.TestMethod(t, r, "POST")
15 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
16
17 w.Header().Set("Content-Type", "application/json")
18 w.WriteHeader(http.StatusOK)
19
20 th.TestJSONRequest(t, r, `
21{
22 "instance": {
23 "databases": [
24 {
25 "character_set": "utf8",
26 "collate": "utf8_general_ci",
27 "name": "sampledb"
28 },
29 {
30 "name": "nextround"
31 }
32 ],
33 "flavorRef": "1",
34 "name": "json_rack_instance",
35 "users": [
36 {
37 "databases": [
38 {
39 "name": "sampledb"
40 }
41 ],
42 "name": "demouser",
43 "password": "demopassword"
44 }
45 ],
46 "volume": {
47 "size": 2
48 },
49 "restorePoint": "1234567890"
50 }
51}
52`)
53
54 fmt.Fprintf(w, `
55{
56 "instance": {
57 "flavorRef": 1,
58 "name": "json_restore",
59 "restorePoint": {
60 "backupRef": "61f12fef-edb1-4561-8122-e7c00ef26a82"
61 },
62 "volume": {
63 "size": 2
64 }
65 }
66}
67`)
68 })
69}