You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
3 years ago
|
package namespace
|
||
3 years ago
|
|
||
3 years ago
|
import (
|
||
|
"testing"
|
||
|
)
|
||
3 years ago
|
|
||
|
|
||
|
func TestQuota(t *testing.T) {
|
||
3 years ago
|
quota := FileSizeQuota { 1000, 0 }
|
||
3 years ago
|
|
||
|
if !quota.Allows(1000) {
|
||
|
t.Errorf("It should allow filling completely")
|
||
|
}
|
||
|
if quota.Allows(1001) {
|
||
|
t.Errorf("It should not allow filling completely")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func TestQuotaManipulation(t *testing.T) {
|
||
3 years ago
|
quota := FileSizeQuota { 1000, 0 }
|
||
3 years ago
|
|
||
|
if quota.Add(500) != nil {
|
||
|
t.Errorf("It should allow adding")
|
||
|
}
|
||
|
|
||
|
if quota.CurrentUsage != 500 {
|
||
|
t.Errorf("It should add the usage correctly")
|
||
|
}
|
||
|
|
||
|
if quota.Add(500) != nil {
|
||
|
t.Errorf("It should allow adding up to the limit")
|
||
|
}
|
||
|
|
||
3 years ago
|
if quota.Add(1) != ErrExceedQuota {
|
||
3 years ago
|
t.Errorf("It should not allow adding beyond limit")
|
||
|
}
|
||
|
|
||
|
if quota.CurrentUsage != 1000 {
|
||
|
t.Errorf("It should not overtaxed after failure to add")
|
||
|
}
|
||
|
|
||
3 years ago
|
if quota.Remove(1001) != ErrQuotaInvalid {
|
||
3 years ago
|
t.Errorf("It should not allow reducing further than 0")
|
||
|
}
|
||
|
|
||
|
if quota.CurrentUsage != 1000 {
|
||
|
t.Errorf("It should not overtaxed after failure to remove")
|
||
|
}
|
||
|
|
||
|
if quota.Remove(1000) != nil {
|
||
|
t.Errorf("It should allow reducing to 0")
|
||
|
}
|
||
|
|
||
|
if quota.CurrentUsage != 0 {
|
||
|
t.Errorf("It should reduce accurately")
|
||
|
}
|
||
|
}
|