chore: simplify tests with logtest (#3184)

This commit is contained in:
Kevin Wan
2023-04-29 20:36:29 +08:00
committed by GitHub
parent c0f8a58ed7
commit 14caf5c799
24 changed files with 223 additions and 315 deletions

View File

@@ -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"))