27 lines
618 B
Go
27 lines
618 B
Go
|
package pkgerrors
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"regexp"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/pkg/errors"
|
||
|
"github.com/rs/zerolog"
|
||
|
)
|
||
|
|
||
|
func TestLogStack(t *testing.T) {
|
||
|
zerolog.ErrorStackMarshaler = MarshalStack
|
||
|
|
||
|
out := &bytes.Buffer{}
|
||
|
log := zerolog.New(out)
|
||
|
|
||
|
err := errors.Wrap(errors.New("error message"), "from error")
|
||
|
log.Log().Stack().Err(err).Msg("")
|
||
|
|
||
|
got := out.String()
|
||
|
want := `\{"stack":\[\{"source":"stacktrace_test.go","line":"18","func":"TestLogStack"\},.*\],"error":"from error: error message"\}\n`
|
||
|
if ok, _ := regexp.MatchString(want, got); !ok {
|
||
|
t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
|
||
|
}
|
||
|
}
|