blob: 653b5c8bf6003524445589364a7ff17d5ec46fb0 [file] [log] [blame]
Jamie Hannaford5b7acc12015-02-13 09:14:25 +01001package flavors
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 HandleListFlavorsSuccessfully(t *testing.T) {
13 th.Mux.HandleFunc("/flavors", func(w http.ResponseWriter, r *http.Request) {
14 th.TestMethod(t, r, "GET")
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 fmt.Fprintf(w, `
21{
22 "flavors": [
23 {
24 "id": 1,
25 "links": [
26 {
27 "href": "https://openstack.example.com/v1.0/1234/flavors/1",
28 "rel": "self"
29 },
30 {
31 "href": "https://openstack.example.com/flavors/1",
32 "rel": "bookmark"
33 }
34 ],
35 "name": "m1.tiny",
36 "ram": 512
37 },
38 {
39 "id": 2,
40 "links": [
41 {
42 "href": "https://openstack.example.com/v1.0/1234/flavors/2",
43 "rel": "self"
44 },
45 {
46 "href": "https://openstack.example.com/flavors/2",
47 "rel": "bookmark"
48 }
49 ],
50 "name": "m1.small",
51 "ram": 1024
52 },
53 {
54 "id": 3,
55 "links": [
56 {
57 "href": "https://openstack.example.com/v1.0/1234/flavors/3",
58 "rel": "self"
59 },
60 {
61 "href": "https://openstack.example.com/flavors/3",
62 "rel": "bookmark"
63 }
64 ],
65 "name": "m1.medium",
66 "ram": 2048
67 },
68 {
69 "id": 4,
70 "links": [
71 {
72 "href": "https://openstack.example.com/v1.0/1234/flavors/4",
73 "rel": "self"
74 },
75 {
76 "href": "https://openstack.example.com/flavors/4",
77 "rel": "bookmark"
78 }
79 ],
80 "name": "m1.large",
81 "ram": 4096
82 }
83 ]
84}
85`)
86 })
87}
88
89func HandleGetFlavorSuccessfully(t *testing.T, flavorID string) {
90 th.Mux.HandleFunc("/flavors/"+flavorID, func(w http.ResponseWriter, r *http.Request) {
91 th.TestMethod(t, r, "GET")
92 th.TestHeader(t, r, "X-Auth-Token", fake.TokenID)
93
94 w.Header().Set("Content-Type", "application/json")
95 w.WriteHeader(http.StatusOK)
96
97 fmt.Fprintf(w, `
98{
99 "flavor": {
100 "id": 1,
101 "links": [
102 {
103 "href": "https://openstack.example.com/v1.0/1234/flavors/1",
104 "rel": "self"
105 }
106 ],
107 "name": "m1.tiny",
108 "ram": 512
109 }
110}
111`)
112 })
113}