Initial cloud-services repo - gateway service + pkg modules
This commit is contained in:
40
pkg/logger/limiter_test.go
Normal file
40
pkg/logger/limiter_test.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package logger_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"fiskerinc.com/modules/logger"
|
||||
"fiskerinc.com/modules/testhelper"
|
||||
)
|
||||
|
||||
func TestLimiter(t *testing.T) {
|
||||
err := errors.New("this is a test")
|
||||
err2 := errors.New("this is a different test")
|
||||
limiter := logger.NewLogLimiter(time.Millisecond*1, 5)
|
||||
|
||||
result := limiter.Check(err.Error())
|
||||
if !result {
|
||||
t.Errorf(testhelper.TestErrorTemplate, "check 1", true, result)
|
||||
}
|
||||
|
||||
result = limiter.Check(err2.Error())
|
||||
if !result {
|
||||
t.Errorf(testhelper.TestErrorTemplate, "check different error", true, result)
|
||||
}
|
||||
|
||||
for i := 0; i < 6; i++ {
|
||||
result = limiter.Check(err.Error())
|
||||
if result {
|
||||
t.Errorf(testhelper.TestErrorTemplate, fmt.Sprintf("check %d", i+2), false, result)
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(time.Millisecond * 1)
|
||||
result = limiter.Check(err.Error())
|
||||
if !result {
|
||||
t.Errorf(testhelper.TestErrorTemplate, "check expired", true, result)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user