2020-07-26 17:09:05 +08:00
|
|
|
package logx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLessLogger_Error(t *testing.T) {
|
2022-05-03 17:34:26 +08:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2022-05-03 17:34:26 +08:00
|
|
|
assert.Equal(t, 1, strings.Count(w.String(), "\n"))
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestLessLogger_Errorf(t *testing.T) {
|
2022-05-03 17:34:26 +08:00
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2022-05-03 17:34:26 +08:00
|
|
|
assert.Equal(t, 1, strings.Count(w.String(), "\n"))
|
2020-07-26 17:09:05 +08:00
|
|
|
}
|