blob: 8f7d1b7256d54b02304942c11b987bc95c60b66a [file] [log] [blame]
Jamie Hannaford9fdda582015-02-10 12:15:43 +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 }
50}
51`)
52
53 fmt.Fprintf(w, `
54{
55 "instance": {
56 "created": "2014-02-13T21:47:13",
57 "datastore": {
58 "type": "mysql",
59 "version": "5.6"
60 },
61 "flavor": {
62 "id": "1",
63 "links": [
64 {
65 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
66 "rel": "self"
67 },
68 {
69 "href": "https://my-openstack.com/v1.0/1234/flavors/1",
70 "rel": "bookmark"
71 }
72 ]
73 },
74 "links": [
75 {
76 "href": "https://my-openstack.com/v1.0/1234/instances/1",
77 "rel": "self"
78 }
79 ],
80 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.my-openstack.com",
81 "id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
82 "name": "json_rack_instance",
83 "status": "BUILD",
84 "updated": "2014-02-13T21:47:13",
85 "volume": {
86 "size": 2
87 }
88 }
89}
90`)
91 })
92}