mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 09:00:20 +08:00
chore: add more tests (#3203)
This commit is contained in:
parent
fe97fab274
commit
42300a7d83
@ -46,7 +46,6 @@ func (b *Buffer) Bytes() []byte {
|
||||
func (b *Buffer) Content() string {
|
||||
var m map[string]interface{}
|
||||
if err := json.Unmarshal(b.buf.Bytes(), &m); err != nil {
|
||||
b.t.Error(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -59,12 +58,8 @@ func (b *Buffer) Content() string {
|
||||
case string:
|
||||
return val
|
||||
default:
|
||||
bs, err := json.Marshal(content)
|
||||
if err != nil {
|
||||
b.t.Error(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// err is impossible to be not nil, unmarshaled from b.buf.Bytes()
|
||||
bs, _ := json.Marshal(content)
|
||||
return string(bs)
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,8 @@ func TestCollector(t *testing.T) {
|
||||
logx.Info(input)
|
||||
assert.Equal(t, input, c.Content())
|
||||
assert.Contains(t, c.String(), input)
|
||||
c.Reset()
|
||||
assert.Empty(t, c.Bytes())
|
||||
}
|
||||
|
||||
func TestPanicOnFatal(t *testing.T) {
|
||||
@ -21,8 +23,22 @@ func TestPanicOnFatal(t *testing.T) {
|
||||
Discard(t)
|
||||
logx.Info(input)
|
||||
|
||||
PanicOnFatal(t)
|
||||
PanicOnFatal(t)
|
||||
assert.Panics(t, func() {
|
||||
logx.Must(errors.New("foo"))
|
||||
})
|
||||
}
|
||||
|
||||
func TestCollectorContent(t *testing.T) {
|
||||
const input = "hello"
|
||||
c := NewCollector(t)
|
||||
c.buf.WriteString(input)
|
||||
assert.Empty(t, c.Content())
|
||||
c.Reset()
|
||||
c.buf.WriteString(`{}`)
|
||||
assert.Empty(t, c.Content())
|
||||
c.Reset()
|
||||
c.buf.WriteString(`{"content":1}`)
|
||||
assert.Equal(t, "1", c.Content())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user