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.
bog/dataswamp/namespace/valueobjects_test.go

42 lines
737 B
Go

package namespace
import (
"github.com/matryer/is"
"testing"
)
func TestQuota(t *testing.T) {
is := is.New(t)
quota := FileSizeQuota{1000, 0}
is.True(quota.Allows(1000))
is.True(!quota.Allows(1001))
}
func TestQuotaManipulation(t *testing.T) {
is := is.New(t)
quota := &FileSizeQuota{1000, 0}
quota, err := quota.Add(500)
is.NoErr(err)
is.Equal(quota.CurrentUsage, int64(500))
quota, err = quota.Add(500)
is.NoErr(err)
_ , err = quota.Add(1)
is.Equal(err, ErrExceedQuota)
is.Equal(quota.CurrentUsage, int64(1000))
_ , err = quota.Remove(1001)
is.Equal(err, ErrQuotaInvalid)
is.Equal(quota.CurrentUsage, int64(1000))
quota, err = quota.Remove(1000)
is.NoErr(err)
is.Equal(quota.CurrentUsage, int64(0))
}