Tests for fileCache
This commit is contained in:
@@ -24,15 +24,12 @@ func NewLimiter(limit int64) *Limiter {
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds n to the limiters internal value, but only if the limit has not been reached. If the limit would be
|
||||
// Add adds n to the limiters internal value, but only if the limit has not been reached. If the limit was
|
||||
// exceeded after adding n, ErrLimitReached is returned.
|
||||
func (l *Limiter) Add(n int64) error {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
if l.limit == 0 {
|
||||
l.value += n
|
||||
return nil
|
||||
} else if l.value+n <= l.limit {
|
||||
if l.value+n <= l.limit {
|
||||
l.value += n
|
||||
return nil
|
||||
} else {
|
||||
|
||||
@@ -127,7 +127,7 @@ func TestParseSize_10GSuccess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, 10*1024*1024*1024, s)
|
||||
require.Equal(t, int64(10*1024*1024*1024), s)
|
||||
}
|
||||
|
||||
func TestParseSize_10MUpperCaseSuccess(t *testing.T) {
|
||||
@@ -135,7 +135,7 @@ func TestParseSize_10MUpperCaseSuccess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, 10*1024*1024, s)
|
||||
require.Equal(t, int64(10*1024*1024), s)
|
||||
}
|
||||
|
||||
func TestParseSize_10kLowerCaseSuccess(t *testing.T) {
|
||||
@@ -143,7 +143,7 @@ func TestParseSize_10kLowerCaseSuccess(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
require.Equal(t, 10*1024, s)
|
||||
require.Equal(t, int64(10*1024), s)
|
||||
}
|
||||
|
||||
func TestParseSize_FailureInvalid(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user