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

@@ -1,12 +1,11 @@
package stat
import (
"bytes"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/logx/logtest"
)
func TestBToMb(t *testing.T) {
@@ -41,15 +40,11 @@ func TestBToMb(t *testing.T) {
}
func TestPrintUsage(t *testing.T) {
var buf bytes.Buffer
writer := logx.NewWriter(&buf)
old := logx.Reset()
logx.SetWriter(writer)
defer logx.SetWriter(old)
c := logtest.NewCollector(t)
printUsage()
output := buf.String()
output := c.String()
assert.Contains(t, output, "CPU:")
assert.Contains(t, output, "MEMORY:")
assert.Contains(t, output, "Alloc=")