go-zero/core/logx/lesslogger_test.go

35 lines
578 B
Go
Raw Normal View History

2020-07-26 17:09:05 +08:00
package logx
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLessLogger_Error(t *testing.T) {
w := new(mockWriter)
old := writer.Swap(w)
defer writer.Store(old)
2020-07-26 17:09:05 +08:00
l := NewLessLogger(500)
for i := 0; i < 100; i++ {
l.Error("hello")
}
assert.Equal(t, 1, strings.Count(w.String(), "\n"))
2020-07-26 17:09:05 +08:00
}
func TestLessLogger_Errorf(t *testing.T) {
w := new(mockWriter)
old := writer.Swap(w)
defer writer.Store(old)
2020-07-26 17:09:05 +08:00
l := NewLessLogger(500)
for i := 0; i < 100; i++ {
l.Errorf("hello")
}
assert.Equal(t, 1, strings.Count(w.String(), "\n"))
2020-07-26 17:09:05 +08:00
}