chore: simplify tests with logtest (#3184)
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/core/logx/logtest"
|
||||
)
|
||||
|
||||
func TestInfo(t *testing.T) {
|
||||
@@ -25,20 +25,11 @@ func TestInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestError(t *testing.T) {
|
||||
var buf strings.Builder
|
||||
w := logx.NewWriter(&buf)
|
||||
o := logx.Reset()
|
||||
logx.SetWriter(w)
|
||||
|
||||
defer func() {
|
||||
logx.Reset()
|
||||
logx.SetWriter(o)
|
||||
}()
|
||||
|
||||
c := logtest.NewCollector(t)
|
||||
req := httptest.NewRequest(http.MethodGet, "http://localhost", http.NoBody)
|
||||
Error(req, "first")
|
||||
Errorf(req, "second %s", "third")
|
||||
val := buf.String()
|
||||
val := c.String()
|
||||
assert.True(t, strings.Contains(val, "first"))
|
||||
assert.True(t, strings.Contains(val, "second"))
|
||||
assert.True(t, strings.Contains(val, "third"))
|
||||
|
||||
Reference in New Issue
Block a user