Skip to content

Commit

Permalink
add a unit test for encode error
Browse files Browse the repository at this point in the history
  • Loading branch information
FMLS committed Nov 4, 2020
1 parent 1c0c739 commit de2b032
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions zapcore/field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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=<nil>"},
{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}
Expand Down

0 comments on commit de2b032

Please sign in to comment.