From de2b032c0d2ef0e152c35b993ca5b1446d8719b2 Mon Sep 17 00:00:00 2001 From: FMLS Date: Wed, 4 Nov 2020 16:58:42 +0800 Subject: [PATCH] add a unit test for encode error --- zapcore/field_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/zapcore/field_test.go b/zapcore/field_test.go index 698138cc4..31de0b623 100644 --- a/zapcore/field_test.go +++ b/zapcore/field_test.go @@ -81,11 +81,16 @@ func (o *obj) String() string { } type errObj struct { - errMessage string + kind int + errMsg string } func (eobj *errObj) Error() string { - return eobj.errMessage + if eobj.kind == 1 { + panic("panic in Error() method") + } else { + return eobj.errMsg + } } func TestUnknownFieldType(t *testing.T) { @@ -110,6 +115,7 @@ func TestFieldAddingError(t *testing.T) { {t: StringerType, iface: &obj{1}, want: empty, err: "PANIC=panic with string"}, {t: StringerType, iface: &obj{2}, want: empty, err: "PANIC=panic with error"}, {t: StringerType, iface: &obj{3}, want: empty, err: "PANIC="}, + {t: ErrorType, iface: &errObj{kind: 1}, want: empty, err: "PANIC=panic in Error() method"}, } for _, tt := range tests { f := Field{Key: "k", Interface: tt.iface, Type: tt.t}