-
Notifications
You must be signed in to change notification settings - Fork 14
/
quota_test.go
150 lines (130 loc) · 3.71 KB
/
quota_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package goisilon
import (
"fmt"
"testing"
)
// Test both GetQuota() and SetQuota()
func TestQuotaGetSet(t *testing.T) {
volumeName := "test_quota_get_set"
quotaSize := int64(12345)
// Setup the test
_, err := client.CreateVolume(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, volumeName)
defer client.ClearQuota(defaultCtx, volumeName)
// Make sure there is no quota yet
quota, err := client.GetQuota(defaultCtx, volumeName)
if quota != nil {
panic(fmt.Sprintf("Quota should be nil: %v", quota))
}
if err == nil {
panic(fmt.Sprintf("GetQuota should return an error when there isn't a quota."))
}
// Set the quota
err = client.SetQuotaSize(defaultCtx, volumeName, quotaSize)
if err != nil {
panic(err)
}
// Make sure the quota was set
quota, err = client.GetQuota(defaultCtx, volumeName)
if err != nil {
panic(err)
}
if quota == nil {
panic("Quota should not be nil")
}
if quota.Thresholds.Hard != quotaSize {
panic(fmt.Sprintf("Unexpected new quota. Expected: %d Actual: %d", quotaSize, quota.Thresholds.Hard))
}
}
// Test UpdateQuota()
func TestQuotaUpdate(t *testing.T) {
volumeName := "test_quota_update"
quotaSize := int64(12345)
updatedQuotaSize := int64(22345000)
// Setup the test
_, err := client.CreateVolume(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, volumeName)
defer client.ClearQuota(defaultCtx, volumeName)
// Set the quota
err = client.SetQuotaSize(defaultCtx, volumeName, quotaSize)
if err != nil {
panic(err)
}
// Make sure the quota is initialized
quota, err := client.GetQuota(defaultCtx, volumeName)
if err != nil {
panic(err)
}
if quota == nil {
panic(fmt.Sprintf("Quota should not be nil: %v", quota))
}
if quota.Thresholds.Hard != quotaSize {
panic(fmt.Sprintf("Initial quota not set properly. Expected: %d Actual: %d", quotaSize, quota.Thresholds.Hard))
}
// Update the quota
err = client.UpdateQuotaSize(defaultCtx, volumeName, updatedQuotaSize)
if err != nil {
panic(err)
}
// Make sure the quota is updated
quota, err = client.GetQuota(defaultCtx, volumeName)
if err != nil {
panic(err)
}
if quota == nil {
panic(fmt.Sprintf("Updated quota should not be nil: %v", quota))
}
if quota.Thresholds.Hard != updatedQuotaSize {
panic(fmt.Sprintf("Updated quota not set properly. Expected: %d Actual: %d", updatedQuotaSize, quota.Thresholds.Hard))
}
}
// Test ClearQuota()
func TestQuotaClear(t *testing.T) {
volumeName := "test_quota_clear"
quotaSize := int64(12345)
// Setup the test
_, err := client.CreateVolume(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// make sure we clean up when we're done
defer client.DeleteVolume(defaultCtx, volumeName)
defer client.ClearQuota(defaultCtx, volumeName)
// Set the quota
err = client.SetQuotaSize(defaultCtx, volumeName, quotaSize)
if err != nil {
panic(err)
}
// Make sure the quota is initialized
quota, err := client.GetQuota(defaultCtx, volumeName)
if err != nil {
panic(err)
}
if quota == nil {
panic(fmt.Sprintf("Quota should not be nil: %v", quota))
}
if quota.Thresholds.Hard != quotaSize {
panic(fmt.Sprintf("Initial quota not set properly. Expected: %d Actual: %d", quotaSize, quota.Thresholds.Hard))
}
// Update the quota
err = client.ClearQuota(defaultCtx, volumeName)
if err != nil {
panic(err)
}
// Make sure the quota is gone
quota, err = client.GetQuota(defaultCtx, volumeName)
if err == nil {
panic(fmt.Sprintf("Attempting to get a cleared quota should return an error but returned nil"))
}
if quota != nil {
panic(fmt.Sprintf("Cleared quota should be nil: %v", quota))
}
}