blob: ac2471eba01f91435072bd88c7d700daa12e7d96 [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
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010012const singleInstanceJson = `
13{
14 "instance": {
15 "created": "2014-02-13T21:47:13",
16 "datastore": {
17 "type": "mysql",
18 "version": "5.6"
19 },
20 "flavor": {
21 "id": "1",
22 "links": [
23 {
24 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
25 "rel": "self"
26 },
27 {
28 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
29 "rel": "bookmark"
30 }
31 ]
32 },
33 "links": [
34 {
35 "href": "https://ord.databases.api.rackspacecloud.com/v1.0/1234/flavors/1",
36 "rel": "self"
37 }
38 ],
39 "hostname": "e09ad9a3f73309469cf1f43d11e79549caf9acf2.rackspaceclouddb.com",
40 "id": "d4603f69-ec7e-4e9b-803f-600b9205576f",
41 "name": "json_rack_instance",
42 "status": "BUILD",
43 "updated": "2014-02-13T21:47:13",
44 "volume": {
45 "size": 2
46 }
47 }
48}
49`
50
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010051func HandleCreateInstanceSuccessfully(t *testing.T) {
52 th.Mux.HandleFunc("/instances", func(w http.ResponseWriter, r *http.Request) {
53 th.TestMethod(t, r, "POST")
54 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
55
56 w.Header().Set("Content-Type", "application/json")
57 w.WriteHeader(http.StatusOK)
58
59 th.TestJSONRequest(t, r, `
60{
61 "instance": {
62 "databases": [
63 {
64 "character_set": "utf8",
65 "collate": "utf8_general_ci",
66 "name": "sampledb"
67 },
68 {
69 "name": "nextround"
70 }
71 ],
72 "flavorRef": "1",
73 "name": "json_rack_instance",
74 "users": [
75 {
76 "databases": [
77 {
78 "name": "sampledb"
79 }
80 ],
81 "name": "demouser",
82 "password": "demopassword"
83 }
84 ],
85 "volume": {
86 "size": 2
87 },
88 "restorePoint": "1234567890"
89 }
90}
91`)
92
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010093 fmt.Fprintf(w, singleInstanceJson)
94 })
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +010095}
Jamie Hannaford39d4ffb2015-02-10 13:19:44 +010096
97func HandleGetInstanceSuccessfully(t *testing.T, id string) {
98 th.Mux.HandleFunc("/instances/"+id, func(w http.ResponseWriter, r *http.Request) {
99 th.TestMethod(t, r, "GET")
100 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
101
102 w.Header().Add("Content-Type", "application/json")
103
104 fmt.Fprintf(w, singleInstanceJson)
Jamie Hannaford6ee7d4a2015-02-09 17:26:49 +0100105 })
106}