(t *testing.T)
| 163 | } |
| 164 | |
| 165 | func TestSugarWithCaptures(t *testing.T) { |
| 166 | type withAny func(*SugaredLogger, ...interface{}) *SugaredLogger |
| 167 | |
| 168 | tests := []struct { |
| 169 | name string |
| 170 | withMethods []withAny |
| 171 | wantJSON []string |
| 172 | }{ |
| 173 | { |
| 174 | name: "with captures arguments at time of With", |
| 175 | withMethods: []withAny{(*SugaredLogger).With}, |
| 176 | wantJSON: []string{ |
| 177 | `{ |
| 178 | "m": "hello 0", |
| 179 | "a0": [0], |
| 180 | "b0": [1] |
| 181 | }`, |
| 182 | `{ |
| 183 | "m": "world 0", |
| 184 | "a0": [0], |
| 185 | "c0": [2] |
| 186 | }`, |
| 187 | }, |
| 188 | }, |
| 189 | { |
| 190 | name: "lazy with captures arguments at time of Logging", |
| 191 | withMethods: []withAny{(*SugaredLogger).WithLazy}, |
| 192 | wantJSON: []string{ |
| 193 | `{ |
| 194 | "m": "hello 0", |
| 195 | "a0": [1], |
| 196 | "b0": [1] |
| 197 | }`, |
| 198 | `{ |
| 199 | "m": "world 0", |
| 200 | "a0": [1], |
| 201 | "c0": [2] |
| 202 | }`, |
| 203 | }, |
| 204 | }, |
| 205 | } |
| 206 | |
| 207 | for _, tt := range tests { |
| 208 | t.Run(tt.name, func(t *testing.T) { |
| 209 | enc := zapcore.NewJSONEncoder(zapcore.EncoderConfig{ |
| 210 | MessageKey: "m", |
| 211 | }) |
| 212 | |
| 213 | var bs ztest.Buffer |
| 214 | logger := New(zapcore.NewCore(enc, &bs, DebugLevel)).Sugar() |
| 215 | |
| 216 | for i, withMethod := range tt.withMethods { |
| 217 | iStr := strconv.Itoa(i) |
| 218 | x := 10 * i |
| 219 | arr := zapcore.ArrayMarshalerFunc(func(enc zapcore.ArrayEncoder) error { |
| 220 | enc.AppendInt(x) |
| 221 | return nil |
| 222 | }) |
nothing calls this directly
no test coverage detected