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.
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
3 years ago
|
package test
|
||
3 years ago
|
|
||
3 years ago
|
import (
|
||
|
"testing"
|
||
|
"caj-larsson/bog/domain"
|
||
|
)
|
||
3 years ago
|
|
||
|
|
||
|
func TestQuota(t *testing.T) {
|
||
3 years ago
|
quota := domain.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 := domain.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) != domain.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) != domain.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")
|
||
|
}
|
||
|
}
|