mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-18 08:26:45 +02:00
54 lines
1.1 KiB
Go
54 lines
1.1 KiB
Go
package logrus
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/drone/drone/Godeps/_workspace/src/github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEntryPanicln(t *testing.T) {
|
|
errBoom := fmt.Errorf("boom time")
|
|
|
|
defer func() {
|
|
p := recover()
|
|
assert.NotNil(t, p)
|
|
|
|
switch pVal := p.(type) {
|
|
case *Entry:
|
|
assert.Equal(t, "kaboom", pVal.Message)
|
|
assert.Equal(t, errBoom, pVal.Data["err"])
|
|
default:
|
|
t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
|
|
}
|
|
}()
|
|
|
|
logger := New()
|
|
logger.Out = &bytes.Buffer{}
|
|
entry := NewEntry(logger)
|
|
entry.WithField("err", errBoom).Panicln("kaboom")
|
|
}
|
|
|
|
func TestEntryPanicf(t *testing.T) {
|
|
errBoom := fmt.Errorf("boom again")
|
|
|
|
defer func() {
|
|
p := recover()
|
|
assert.NotNil(t, p)
|
|
|
|
switch pVal := p.(type) {
|
|
case *Entry:
|
|
assert.Equal(t, "kaboom true", pVal.Message)
|
|
assert.Equal(t, errBoom, pVal.Data["err"])
|
|
default:
|
|
t.Fatalf("want type *Entry, got %T: %#v", pVal, pVal)
|
|
}
|
|
}()
|
|
|
|
logger := New()
|
|
logger.Out = &bytes.Buffer{}
|
|
entry := NewEntry(logger)
|
|
entry.WithField("err", errBoom).Panicf("kaboom %v", true)
|
|
}
|