lesslogger_test.go 563 B

12345678910111213141516171819202122232425262728293031
  1. package logx
  2. import (
  3. "log"
  4. "strings"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestLessLogger_Error(t *testing.T) {
  9. var builder strings.Builder
  10. log.SetOutput(&builder)
  11. l := NewLessLogger(500)
  12. for i := 0; i < 100; i++ {
  13. l.Error("hello")
  14. }
  15. assert.Equal(t, 1, strings.Count(builder.String(), "\n"))
  16. }
  17. func TestLessLogger_Errorf(t *testing.T) {
  18. var builder strings.Builder
  19. log.SetOutput(&builder)
  20. l := NewLessLogger(500)
  21. for i := 0; i < 100; i++ {
  22. l.Errorf("hello")
  23. }
  24. assert.Equal(t, 1, strings.Count(builder.String(), "\n"))
  25. }