2023-04-29 20:36:29 +08:00
|
|
|
package logtest
|
|
|
|
|
|
|
|
|
|
import (
|
2023-04-29 22:59:07 +08:00
|
|
|
"errors"
|
2023-04-29 20:36:29 +08:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCollector(t *testing.T) {
|
|
|
|
|
const input = "hello"
|
|
|
|
|
c := NewCollector(t)
|
|
|
|
|
logx.Info(input)
|
|
|
|
|
assert.Equal(t, input, c.Content())
|
|
|
|
|
assert.Contains(t, c.String(), input)
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-29 22:59:07 +08:00
|
|
|
func TestPanicOnFatal(t *testing.T) {
|
2023-04-29 20:36:29 +08:00
|
|
|
const input = "hello"
|
|
|
|
|
Discard(t)
|
|
|
|
|
logx.Info(input)
|
2023-04-29 22:59:07 +08:00
|
|
|
|
|
|
|
|
PanicOnFatal(t)
|
|
|
|
|
assert.Panics(t, func() {
|
|
|
|
|
logx.Must(errors.New("foo"))
|
|
|
|
|
})
|
2023-04-29 20:36:29 +08:00
|
|
|
}
|