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
package namespace
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
|
|
func TestQuota(t *testing.T) {
|
|
quota := FileSizeQuota { 1000, 0 }
|
|
|
|
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) {
|
|
quota := FileSizeQuota { 1000, 0 }
|
|
|
|
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")
|
|
}
|
|
|
|
if quota.Add(1) != ErrExceedQuota {
|
|
t.Errorf("It should not allow adding beyond limit")
|
|
}
|
|
|
|
if quota.CurrentUsage != 1000 {
|
|
t.Errorf("It should not overtaxed after failure to add")
|
|
}
|
|
|
|
if quota.Remove(1001) != ErrQuotaInvalid {
|
|
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")
|
|
}
|
|
}
|