logtest_test.go 839 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package logtest
  2. import (
  3. "errors"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/wuntsong-org/go-zero-plus/core/logx"
  7. )
  8. func TestCollector(t *testing.T) {
  9. const input = "hello"
  10. c := NewCollector(t)
  11. logx.Info(input)
  12. assert.Equal(t, input, c.Content())
  13. assert.Contains(t, c.String(), input)
  14. c.Reset()
  15. assert.Empty(t, c.Bytes())
  16. }
  17. func TestPanicOnFatal(t *testing.T) {
  18. const input = "hello"
  19. Discard(t)
  20. logx.Info(input)
  21. PanicOnFatal(t)
  22. PanicOnFatal(t)
  23. assert.Panics(t, func() {
  24. logx.Must(errors.New("foo"))
  25. })
  26. }
  27. func TestCollectorContent(t *testing.T) {
  28. const input = "hello"
  29. c := NewCollector(t)
  30. c.buf.WriteString(input)
  31. assert.Empty(t, c.Content())
  32. c.Reset()
  33. c.buf.WriteString(`{}`)
  34. assert.Empty(t, c.Content())
  35. c.Reset()
  36. c.buf.WriteString(`{"content":1}`)
  37. assert.Equal(t, "1", c.Content())
  38. }