Files
cloud-services/pkg/logger/limiter_test.go

41 lines
906 B
Go

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