blob: a410af9d8981e2b19f088d98893cfadc311b3121 [file] [log] [blame]
Ildar Svetlov9ae28ba2020-03-27 15:01:41 +04001package testing
2
3import (
4 "fmt"
5 "net/http"
6 "testing"
7
8 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
9 "gerrit.mcp.mirantis.net/debian/gophercloud.git/openstack/blockstorage/extensions/quotasets"
10 th "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper"
11 "gerrit.mcp.mirantis.net/debian/gophercloud.git/testhelper/client"
12)
13
14const FirstTenantID = "555544443333222211110000ffffeeee"
15
16var getExpectedJSONBody = `
17{
18 "quota_set" : {
19 "volumes" : 8,
20 "snapshots" : 9,
21 "gigabytes" : 10,
22 "per_volume_gigabytes" : 11,
23 "backups" : 12,
24 "backup_gigabytes" : 13,
25 "groups": 14
26 }
27}`
28
29var getExpectedQuotaSet = quotasets.QuotaSet{
30 Volumes: 8,
31 Snapshots: 9,
32 Gigabytes: 10,
33 PerVolumeGigabytes: 11,
34 Backups: 12,
35 BackupGigabytes: 13,
36 Groups: 14,
37}
38
39var getUsageExpectedJSONBody = `
40{
41 "quota_set" : {
42 "id": "555544443333222211110000ffffeeee",
43 "volumes" : {
44 "in_use": 15,
45 "limit": 16,
46 "reserved": 17
47 },
48 "snapshots" : {
49 "in_use": 18,
50 "limit": 19,
51 "reserved": 20
52 },
53 "gigabytes" : {
54 "in_use": 21,
55 "limit": 22,
56 "reserved": 23
57 },
58 "per_volume_gigabytes" : {
59 "in_use": 24,
60 "limit": 25,
61 "reserved": 26
62 },
63 "backups" : {
64 "in_use": 27,
65 "limit": 28,
66 "reserved": 29
67 },
68 "backup_gigabytes" : {
69 "in_use": 30,
70 "limit": 31,
71 "reserved": 32
72 },
73 "groups" : {
74 "in_use": 40,
75 "limit": 41,
76 "reserved": 42
77 }
78 }
79}`
80
81var getUsageExpectedQuotaSet = quotasets.QuotaUsageSet{
82 ID: FirstTenantID,
83 Volumes: quotasets.QuotaUsage{InUse: 15, Limit: 16, Reserved: 17},
84 Snapshots: quotasets.QuotaUsage{InUse: 18, Limit: 19, Reserved: 20},
85 Gigabytes: quotasets.QuotaUsage{InUse: 21, Limit: 22, Reserved: 23},
86 PerVolumeGigabytes: quotasets.QuotaUsage{InUse: 24, Limit: 25, Reserved: 26},
87 Backups: quotasets.QuotaUsage{InUse: 27, Limit: 28, Reserved: 29},
88 BackupGigabytes: quotasets.QuotaUsage{InUse: 30, Limit: 31, Reserved: 32},
89 Groups: quotasets.QuotaUsage{InUse: 40, Limit: 41, Reserved: 42},
90}
91
92var fullUpdateExpectedJSONBody = `
93{
94 "quota_set": {
95 "volumes": 8,
96 "snapshots": 9,
97 "gigabytes": 10,
98 "per_volume_gigabytes": 11,
99 "backups": 12,
100 "backup_gigabytes": 13,
101 "groups": 14
102 }
103}`
104
105var fullUpdateOpts = quotasets.UpdateOpts{
106 Volumes: gophercloud.IntToPointer(8),
107 Snapshots: gophercloud.IntToPointer(9),
108 Gigabytes: gophercloud.IntToPointer(10),
109 PerVolumeGigabytes: gophercloud.IntToPointer(11),
110 Backups: gophercloud.IntToPointer(12),
111 BackupGigabytes: gophercloud.IntToPointer(13),
112 Groups: gophercloud.IntToPointer(14),
113}
114
115var fullUpdateExpectedQuotaSet = quotasets.QuotaSet{
116 Volumes: 8,
117 Snapshots: 9,
118 Gigabytes: 10,
119 PerVolumeGigabytes: 11,
120 Backups: 12,
121 BackupGigabytes: 13,
122 Groups: 14,
123}
124
125var partialUpdateExpectedJSONBody = `
126{
127 "quota_set": {
128 "volumes": 200,
129 "snapshots": 0,
130 "gigabytes": 0,
131 "per_volume_gigabytes": 0,
132 "backups": 0,
133 "backup_gigabytes": 0
134 }
135}`
136
137var partialUpdateOpts = quotasets.UpdateOpts{
138 Volumes: gophercloud.IntToPointer(200),
139 Snapshots: gophercloud.IntToPointer(0),
140 Gigabytes: gophercloud.IntToPointer(0),
141 PerVolumeGigabytes: gophercloud.IntToPointer(0),
142 Backups: gophercloud.IntToPointer(0),
143 BackupGigabytes: gophercloud.IntToPointer(0),
144}
145
146var partiualUpdateExpectedQuotaSet = quotasets.QuotaSet{Volumes: 200}
147
148// HandleSuccessfulRequest configures the test server to respond to an HTTP request.
149func HandleSuccessfulRequest(t *testing.T, httpMethod, uriPath, jsonOutput string, uriQueryParams map[string]string) {
150
151 th.Mux.HandleFunc(uriPath, func(w http.ResponseWriter, r *http.Request) {
152 th.TestMethod(t, r, httpMethod)
153 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
154 w.Header().Add("Content-Type", "application/json")
155
156 if uriQueryParams != nil {
157 th.TestFormValues(t, r, uriQueryParams)
158 }
159
160 fmt.Fprintf(w, jsonOutput)
161 })
162}
163
164// HandleDeleteSuccessfully tests quotaset deletion.
165func HandleDeleteSuccessfully(t *testing.T) {
166 th.Mux.HandleFunc("/os-quota-sets/"+FirstTenantID, func(w http.ResponseWriter, r *http.Request) {
167 th.TestMethod(t, r, "DELETE")
168 th.TestHeader(t, r, "X-Auth-Token", client.TokenID)
169
170 w.WriteHeader(http.StatusOK)
171 })
172}