blob: 0945f9be384067486723cbadc9f7a0d81daf318d [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Dan Kirkwoodceb84092016-03-01 13:58:34 -07002
3import (
4 "fmt"
5 "net/http"
6 "testing"
jrperritt3d966162016-06-06 14:08:54 -05007 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
8 th "github.com/gophercloud/gophercloud/testhelper"
9 "github.com/gophercloud/gophercloud/testhelper/client"
dbaumgartenc2bb4912017-01-19 17:14:08 +010010 "github.com/gophercloud/gophercloud"
Dan Kirkwoodceb84092016-03-01 13:58:34 -070011)
12
13// GetOutput is a sample response to a Get call.
14const GetOutput = `
15{
16 "quota_set" : {
17 "instances" : 25,
18 "security_groups" : 10,
19 "security_group_rules" : 20,
20 "cores" : 200,
21 "injected_file_content_bytes" : 10240,
22 "injected_files" : 5,
23 "metadata_items" : 128,
24 "ram" : 200000,
dbaumgartenc2bb4912017-01-19 17:14:08 +010025 "key_pairs" : 10,
26 "injected_file_path_bytes" : 255,
27 "server_groups" : 2,
28 "server_group_members" : 3
Dan Kirkwoodceb84092016-03-01 13:58:34 -070029 }
30}
31`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070032const FirstTenantID = "555544443333222211110000ffffeeee"
33
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070034// FirstQuotaSet is the first result in ListOutput.
jrperritt3d966162016-06-06 14:08:54 -050035var FirstQuotaSet = quotasets.QuotaSet{
Dan Kirkwoodceb84092016-03-01 13:58:34 -070036 FixedIps: 0,
37 FloatingIps: 0,
38 InjectedFileContentBytes: 10240,
39 InjectedFilePathBytes: 255,
40 InjectedFiles: 5,
41 KeyPairs: 10,
42 MetadataItems: 128,
43 Ram: 200000,
44 SecurityGroupRules: 20,
45 SecurityGroups: 10,
46 Cores: 200,
47 Instances: 25,
dbaumgartenc2bb4912017-01-19 17:14:08 +010048 ServerGroups: 2,
49 ServerGroupMembers: 3,
50}
51
52
53//The expected update Body. Is also returned by PUT request
54const UpdateOutput = `{"quota_set":{"cores":200,"fixed_ips":0,"floating_ips":0,"injected_file_content_bytes":10240,"injected_file_path_bytes":255,"injected_files":5,"instances":25,"key_pairs":10,"metadata_items":128,"ram":200000,"security_group_rules":20,"security_groups":10,"server_groups":2,"server_group_members":3}}`
55
56//The expected partialupdate Body. Is also returned by PUT request
57const PartialUpdateBody = `{"quota_set":{"cores":200, "force":true}}`
58
59
60//Result of Quota-update
61var UpdatedQuotaSet = quotasets.UpdateOpts{
62 FixedIps: gophercloud.IntToPointer(0),
63 FloatingIps: gophercloud.IntToPointer(0),
64 InjectedFileContentBytes: gophercloud.IntToPointer(10240),
65 InjectedFilePathBytes: gophercloud.IntToPointer(255),
66 InjectedFiles: gophercloud.IntToPointer(5),
67 KeyPairs: gophercloud.IntToPointer(10),
68 MetadataItems: gophercloud.IntToPointer(128),
69 Ram: gophercloud.IntToPointer(200000),
70 SecurityGroupRules: gophercloud.IntToPointer(20),
71 SecurityGroups: gophercloud.IntToPointer(10),
72 Cores: gophercloud.IntToPointer(200),
73 Instances: gophercloud.IntToPointer(25),
74 ServerGroups: gophercloud.IntToPointer(2),
75 ServerGroupMembers: gophercloud.IntToPointer(3),
Dan Kirkwoodceb84092016-03-01 13:58:34 -070076}
77
78// HandleGetSuccessfully configures the test server to respond to a Get request for sample tenant
79func HandleGetSuccessfully(t *testing.T) {
80 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
81 th.TestMethod(t, r, "GET")
82 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
83
84 w.Header().Add("Content-Type", "application/json")
85 fmt.Fprintf(w, GetOutput)
86 })
87}
dbaumgartenc2bb4912017-01-19 17:14:08 +010088
89// HandlePutSuccessfully configures the test server to respond to a Put request for sample tenant
90func HandlePutSuccessfully(t *testing.T) {
91 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
92 th.TestMethod(t, r, "PUT")
93 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
94 th.TestJSONRequest(t,r,UpdateOutput)
95 w.Header().Add("Content-Type", "application/json")
96 fmt.Fprintf(w, UpdateOutput)
97 })
98}
99
100// HandlePartialPutSuccessfully configures the test server to respond to a Put request for sample tenant that only containes specific values
101func HandlePartialPutSuccessfully(t *testing.T) {
102 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
103 th.TestMethod(t, r, "PUT")
104 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
105 th.TestJSONRequest(t,r,PartialUpdateBody)
106 w.Header().Add("Content-Type", "application/json")
107 fmt.Fprintf(w, UpdateOutput)
108 })
109}
110
111// HandleDeleteSuccessfully configures the test server to respond to a Delete request for sample tenant
112func HandleDeleteSuccessfully(t *testing.T) {
113 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
114 th.TestMethod(t, r, "DELETE")
115 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
116 th.TestBody(t,r,"")
117 w.Header().Add("Content-Type", "application/json")
118 w.WriteHeader(202)
119 })
120}