blob: 79537ab6d0913474efa398acf6bd2f29f4a51fb2 [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": {
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010057 "created": "2014-02-13T21:47:13",
58 "datastore": {
59 "type": "mysql",
60 "version": "5.6"
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010061 },
Jamie Hannaford3dbfb2d2015-02-10 11:06:47 +010062 "flavor": {
63 "id": "1",
64 "links": [
65 {
66 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
67 "rel": "self"
68 },
69 {
70 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
71 "rel": "bookmark"
72 }
73 ]
74 },
75 "links": [
76 {
77 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
78 "rel": "self"
79 }
80 ],
81 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
82 "id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
83 "name": "json_rack_instance",
84 "status": "BUILD",
85 "updated": "2014-02-13T21:47:13",
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010086 "volume": {
87 "size": 2
88 }
89 }
90}
91`)
92 })
93}