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)) }