Skip to content

Commit

Permalink
Add direct coverage to zap.Any (#1309)
Browse files Browse the repository at this point in the history
Practically, the cases added are today covered by the tests for strongly
typed functions, but are missing if someone was to do a refactoring like
#1305 or #1307.

More theoretically, since `zap.Any` is an external interface, IMO it
makes sense to test it separately too.
  • Loading branch information
rabbbit committed Jul 30, 2023
1 parent 8d1bd8c commit 8db347b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions field_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func TestFieldConstructors(t *testing.T) {
uint16Val = uint16(1)
uint8Val = uint8(1)
uintptrVal = uintptr(1)
nilErr error
)

tests := []struct {
Expand Down Expand Up @@ -166,6 +167,7 @@ func TestFieldConstructors(t *testing.T) {
{"Any:Uintptr", Any("k", uintptr(1)), Uintptr("k", 1)},
{"Any:Uintptrs", Any("k", []uintptr{1}), Uintptrs("k", []uintptr{1})},
{"Any:Time", Any("k", time.Unix(0, 0)), Time("k", time.Unix(0, 0))},
{"Any:TimeFullType", Any("k", time.Time{}), Time("k", time.Time{})},
{"Any:Times", Any("k", []time.Time{time.Unix(0, 0)}), Times("k", []time.Time{time.Unix(0, 0)})},
{"Any:Duration", Any("k", time.Second), Duration("k", time.Second)},
{"Any:Durations", Any("k", []time.Duration{time.Second}), Durations("k", []time.Duration{time.Second})},
Expand Down Expand Up @@ -222,6 +224,7 @@ func TestFieldConstructors(t *testing.T) {
{"Ptr:Time", Timep("k", &timeVal), Time("k", timeVal)},
{"Any:PtrTime", Any("k", (*time.Time)(nil)), nilField("k")},
{"Any:PtrTime", Any("k", &timeVal), Time("k", timeVal)},
{"Any:PtrTimeFullType", Any("k", &time.Time{}), Time("k", time.Time{})},
{"Ptr:Uint", Uintp("k", nil), nilField("k")},
{"Ptr:Uint", Uintp("k", &uintVal), Uint("k", uintVal)},
{"Any:PtrUint", Any("k", (*uint)(nil)), nilField("k")},
Expand All @@ -246,6 +249,7 @@ func TestFieldConstructors(t *testing.T) {
{"Ptr:Uintptr", Uintptrp("k", &uintptrVal), Uintptr("k", uintptrVal)},
{"Any:PtrUintptr", Any("k", (*uintptr)(nil)), nilField("k")},
{"Any:PtrUintptr", Any("k", &uintptrVal), Uintptr("k", uintptrVal)},
{"Any:ErrorNil", Any("k", nilErr), nilField("k")},
{"Namespace", Namespace("k"), Field{Key: "k", Type: zapcore.NamespaceType}},
}

Expand Down

0 comments on commit 8db347b

Please sign in to comment.