MCPcopy
hub / github.com/uber-go/zap / TestFieldConstructors

Function TestFieldConstructors

field_test.go:63–267  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

61}
62
63func TestFieldConstructors(t *testing.T) {
64 // Interface types.
65 addr := net.ParseIP("1.2.3.4")
66 name := username("phil")
67 ints := []int{5, 6}
68
69 // Helpful values for use in constructing pointers to primitives below.
70 var (
71 boolVal = bool(true)
72 complex128Val = complex128(complex(0, 0))
73 complex64Val = complex64(complex(0, 0))
74 durationVal = time.Duration(time.Second)
75 float64Val = float64(1.0)
76 float32Val = float32(1.0)
77 intVal = int(1)
78 int64Val = int64(1)
79 int32Val = int32(1)
80 int16Val = int16(1)
81 int8Val = int8(1)
82 stringVal = string("hello")
83 timeVal = time.Unix(100000, 0)
84 uintVal = uint(1)
85 uint64Val = uint64(1)
86 uint32Val = uint32(1)
87 uint16Val = uint16(1)
88 uint8Val = uint8(1)
89 uintptrVal = uintptr(1)
90 nilErr error
91 )
92
93 tests := []struct {
94 name string
95 field Field
96 expect Field
97 }{
98 {"Skip", Field{Type: zapcore.SkipType}, Skip()},
99 {"Binary", Field{Key: "k", Type: zapcore.BinaryType, Interface: []byte("ab12")}, Binary("k", []byte("ab12"))},
100 {"Bool", Field{Key: "k", Type: zapcore.BoolType, Integer: 1}, Bool("k", true)},
101 {"Bool", Field{Key: "k", Type: zapcore.BoolType, Integer: 0}, Bool("k", false)},
102 {"ByteString", Field{Key: "k", Type: zapcore.ByteStringType, Interface: []byte("ab12")}, ByteString("k", []byte("ab12"))},
103 {"Complex128", Field{Key: "k", Type: zapcore.Complex128Type, Interface: 1 + 2i}, Complex128("k", 1+2i)},
104 {"Complex64", Field{Key: "k", Type: zapcore.Complex64Type, Interface: complex64(1 + 2i)}, Complex64("k", 1+2i)},
105 {"Duration", Field{Key: "k", Type: zapcore.DurationType, Integer: 1}, Duration("k", 1)},
106 {"Int", Field{Key: "k", Type: zapcore.Int64Type, Integer: 1}, Int("k", 1)},
107 {"Int64", Field{Key: "k", Type: zapcore.Int64Type, Integer: 1}, Int64("k", 1)},
108 {"Int32", Field{Key: "k", Type: zapcore.Int32Type, Integer: 1}, Int32("k", 1)},
109 {"Int16", Field{Key: "k", Type: zapcore.Int16Type, Integer: 1}, Int16("k", 1)},
110 {"Int8", Field{Key: "k", Type: zapcore.Int8Type, Integer: 1}, Int8("k", 1)},
111 {"String", Field{Key: "k", Type: zapcore.StringType, String: "foo"}, String("k", "foo")},
112 {"Time", Field{Key: "k", Type: zapcore.TimeType, Integer: 0, Interface: time.UTC}, Time("k", time.Unix(0, 0).In(time.UTC))},
113 {"Time", Field{Key: "k", Type: zapcore.TimeType, Integer: 1000, Interface: time.UTC}, Time("k", time.Unix(0, 1000).In(time.UTC))},
114 {"Time", Field{Key: "k", Type: zapcore.TimeType, Integer: math.MinInt64, Interface: time.UTC}, Time("k", time.Unix(0, math.MinInt64).In(time.UTC))},
115 {"Time", Field{Key: "k", Type: zapcore.TimeType, Integer: math.MaxInt64, Interface: time.UTC}, Time("k", time.Unix(0, math.MaxInt64).In(time.UTC))},
116 {"Time", Field{Key: "k", Type: zapcore.TimeFullType, Interface: time.Time{}}, Time("k", time.Time{})},
117 {"Time", Field{Key: "k", Type: zapcore.TimeFullType, Interface: time.Unix(math.MaxInt64, 0)}, Time("k", time.Unix(math.MaxInt64, 0))},
118 {"Uint", Field{Key: "k", Type: zapcore.Uint64Type, Integer: 1}, Uint("k", 1)},
119 {"Uint64", Field{Key: "k", Type: zapcore.Uint64Type, Integer: 1}, Uint64("k", 1)},
120 {"Uint32", Field{Key: "k", Type: zapcore.Uint32Type, Integer: 1}, Uint32("k", 1)},

Callers

nothing calls this directly

Calls 15

usernameTypeAlias · 0.85
SkipFunction · 0.85
BinaryFunction · 0.85
BoolFunction · 0.85
ByteStringFunction · 0.85
Complex128Function · 0.85
Complex64Function · 0.85
DurationFunction · 0.85
IntFunction · 0.85
Int64Function · 0.85
Int32Function · 0.85
Int16Function · 0.85

Tested by

no test coverage detected