blob: 79305a74608c0513fe761d339e1b3ed806525a47 [file] [log] [blame]
jrperritt3d966162016-06-06 14:08:54 -05001package testing
Dan Kirkwoodceb84092016-03-01 13:58:34 -07002
3import (
4 "fmt"
jrperritt5cb543c2017-02-20 14:03:36 -06005 "github.com/gophercloud/gophercloud"
jrperritt3d966162016-06-06 14:08:54 -05006 "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/quotasets"
7 th "github.com/gophercloud/gophercloud/testhelper"
8 "github.com/gophercloud/gophercloud/testhelper/client"
jrperritt5cb543c2017-02-20 14:03:36 -06009 "net/http"
10 "testing"
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,
jrperritt5cb543c2017-02-20 14:03:36 -060048 ServerGroups: 2,
dbaumgartenc2bb4912017-01-19 17:14:08 +010049 ServerGroupMembers: 3,
50}
51
dbaumgartenc2bb4912017-01-19 17:14:08 +010052//The expected update Body. Is also returned by PUT request
53const 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}}`
54
55//The expected partialupdate Body. Is also returned by PUT request
56const PartialUpdateBody = `{"quota_set":{"cores":200, "force":true}}`
57
dbaumgartenc2bb4912017-01-19 17:14:08 +010058//Result of Quota-update
59var UpdatedQuotaSet = quotasets.UpdateOpts{
60 FixedIps: gophercloud.IntToPointer(0),
61 FloatingIps: gophercloud.IntToPointer(0),
62 InjectedFileContentBytes: gophercloud.IntToPointer(10240),
63 InjectedFilePathBytes: gophercloud.IntToPointer(255),
64 InjectedFiles: gophercloud.IntToPointer(5),
65 KeyPairs: gophercloud.IntToPointer(10),
66 MetadataItems: gophercloud.IntToPointer(128),
67 Ram: gophercloud.IntToPointer(200000),
68 SecurityGroupRules: gophercloud.IntToPointer(20),
69 SecurityGroups: gophercloud.IntToPointer(10),
70 Cores: gophercloud.IntToPointer(200),
71 Instances: gophercloud.IntToPointer(25),
jrperritt5cb543c2017-02-20 14:03:36 -060072 ServerGroups: gophercloud.IntToPointer(2),
dbaumgartenc2bb4912017-01-19 17:14:08 +010073 ServerGroupMembers: gophercloud.IntToPointer(3),
Dan Kirkwoodceb84092016-03-01 13:58:34 -070074}
75
76// HandleGetSuccessfully configures the test server to respond to a Get request for sample tenant
77func HandleGetSuccessfully(t *testing.T) {
78 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
79 th.TestMethod(t, r, "GET")
80 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
81
82 w.Header().Add("Content-Type", "application/json")
83 fmt.Fprintf(w, GetOutput)
84 })
85}
dbaumgartenc2bb4912017-01-19 17:14:08 +010086
87// HandlePutSuccessfully configures the test server to respond to a Put request for sample tenant
88func HandlePutSuccessfully(t *testing.T) {
89 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
90 th.TestMethod(t, r, "PUT")
91 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
jrperritt5cb543c2017-02-20 14:03:36 -060092 th.TestJSONRequest(t, r, UpdateOutput)
dbaumgartenc2bb4912017-01-19 17:14:08 +010093 w.Header().Add("Content-Type", "application/json")
94 fmt.Fprintf(w, UpdateOutput)
95 })
96}
97
98// HandlePartialPutSuccessfully configures the test server to respond to a Put request for sample tenant that only containes specific values
99func HandlePartialPutSuccessfully(t *testing.T) {
100 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
101 th.TestMethod(t, r, "PUT")
102 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
jrperritt5cb543c2017-02-20 14:03:36 -0600103 th.TestJSONRequest(t, r, PartialUpdateBody)
dbaumgartenc2bb4912017-01-19 17:14:08 +0100104 w.Header().Add("Content-Type", "application/json")
105 fmt.Fprintf(w, UpdateOutput)
106 })
107}
108
109// HandleDeleteSuccessfully configures the test server to respond to a Delete request for sample tenant
110func HandleDeleteSuccessfully(t *testing.T) {
111 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
112 th.TestMethod(t, r, "DELETE")
113 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
jrperritt5cb543c2017-02-20 14:03:36 -0600114 th.TestBody(t, r, "")
dbaumgartenc2bb4912017-01-19 17:14:08 +0100115 w.Header().Add("Content-Type", "application/json")
116 w.WriteHeader(202)
117 })
jrperritt5cb543c2017-02-20 14:03:36 -0600118}