Remove vendor directory and add it to the ignore list
This commit is contained in:
73
vendor/github.com/hpcloud/tail/ratelimiter/leakybucket_test.go
generated
vendored
73
vendor/github.com/hpcloud/tail/ratelimiter/leakybucket_test.go
generated
vendored
@@ -1,73 +0,0 @@
|
||||
package ratelimiter
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestPour(t *testing.T) {
|
||||
bucket := NewLeakyBucket(60, time.Second)
|
||||
bucket.Lastupdate = time.Unix(0, 0)
|
||||
|
||||
bucket.Now = func() time.Time { return time.Unix(1, 0) }
|
||||
|
||||
if bucket.Pour(61) {
|
||||
t.Error("Expected false")
|
||||
}
|
||||
|
||||
if !bucket.Pour(10) {
|
||||
t.Error("Expected true")
|
||||
}
|
||||
|
||||
if !bucket.Pour(49) {
|
||||
t.Error("Expected true")
|
||||
}
|
||||
|
||||
if bucket.Pour(2) {
|
||||
t.Error("Expected false")
|
||||
}
|
||||
|
||||
bucket.Now = func() time.Time { return time.Unix(61, 0) }
|
||||
if !bucket.Pour(60) {
|
||||
t.Error("Expected true")
|
||||
}
|
||||
|
||||
if bucket.Pour(1) {
|
||||
t.Error("Expected false")
|
||||
}
|
||||
|
||||
bucket.Now = func() time.Time { return time.Unix(70, 0) }
|
||||
|
||||
if !bucket.Pour(1) {
|
||||
t.Error("Expected true")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestTimeSinceLastUpdate(t *testing.T) {
|
||||
bucket := NewLeakyBucket(60, time.Second)
|
||||
bucket.Now = func() time.Time { return time.Unix(1, 0) }
|
||||
bucket.Pour(1)
|
||||
bucket.Now = func() time.Time { return time.Unix(2, 0) }
|
||||
|
||||
sinceLast := bucket.TimeSinceLastUpdate()
|
||||
if sinceLast != time.Second*1 {
|
||||
t.Errorf("Expected time since last update to be less than 1 second, got %d", sinceLast)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTimeToDrain(t *testing.T) {
|
||||
bucket := NewLeakyBucket(60, time.Second)
|
||||
bucket.Now = func() time.Time { return time.Unix(1, 0) }
|
||||
bucket.Pour(10)
|
||||
|
||||
if bucket.TimeToDrain() != time.Second*10 {
|
||||
t.Error("Time to drain should be 10 seconds")
|
||||
}
|
||||
|
||||
bucket.Now = func() time.Time { return time.Unix(2, 0) }
|
||||
|
||||
if bucket.TimeToDrain() != time.Second*9 {
|
||||
t.Error("Time to drain should be 9 seconds")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user