chore: add more tests (#3187)
This commit is contained in:
@@ -76,3 +76,14 @@ func (b *Buffer) Reset() {
|
||||
func (b *Buffer) String() string {
|
||||
return b.buf.String()
|
||||
}
|
||||
|
||||
func PanicOnFatal(t *testing.T) {
|
||||
ok := logx.ExitOnFatal.CompareAndSwap(true, false)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
t.Cleanup(func() {
|
||||
logx.ExitOnFatal.CompareAndSwap(false, true)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package logtest
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -15,8 +16,13 @@ func TestCollector(t *testing.T) {
|
||||
assert.Contains(t, c.String(), input)
|
||||
}
|
||||
|
||||
func TestDiscard(t *testing.T) {
|
||||
func TestPanicOnFatal(t *testing.T) {
|
||||
const input = "hello"
|
||||
Discard(t)
|
||||
logx.Info(input)
|
||||
|
||||
PanicOnFatal(t)
|
||||
assert.Panics(t, func() {
|
||||
logx.Must(errors.New("foo"))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@ func ForAtomicBool(val bool) *AtomicBool {
|
||||
// CompareAndSwap compares current value with given old, if equals, set to given val.
|
||||
func (b *AtomicBool) CompareAndSwap(old, val bool) bool {
|
||||
var ov, nv uint32
|
||||
|
||||
if old {
|
||||
ov = 1
|
||||
}
|
||||
if val {
|
||||
nv = 1
|
||||
}
|
||||
|
||||
return atomic.CompareAndSwapUint32((*uint32)(b), ov, nv)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user