(t *testing.T)
| 317 | } |
| 318 | |
| 319 | func TestDictObject(t *testing.T) { |
| 320 | tests := []struct { |
| 321 | desc string |
| 322 | field Field |
| 323 | expected any |
| 324 | }{ |
| 325 | { |
| 326 | "empty", |
| 327 | Object("", DictObject()), |
| 328 | map[string]any{}, |
| 329 | }, |
| 330 | { |
| 331 | "object", |
| 332 | Object("", DictObject(String("k", "v"))), |
| 333 | map[string]any{"k": "v"}, |
| 334 | }, |
| 335 | { |
| 336 | "objects", |
| 337 | Objects("", []zapcore.ObjectMarshaler{ |
| 338 | DictObject(String("k", "v")), |
| 339 | DictObject(String("k2", "v2")), |
| 340 | }), |
| 341 | []any{ |
| 342 | map[string]any{"k": "v"}, |
| 343 | map[string]any{"k2": "v2"}, |
| 344 | }, |
| 345 | }, |
| 346 | } |
| 347 | |
| 348 | for _, tt := range tests { |
| 349 | t.Run(tt.desc, func(t *testing.T) { |
| 350 | enc := zapcore.NewMapObjectEncoder() |
| 351 | tt.field.Key = "k" |
| 352 | tt.field.AddTo(enc) |
| 353 | assert.Equal(t, tt.expected, enc.Fields["k"], "unexpected map contents") |
| 354 | assert.Len(t, enc.Fields, 1, "found extra keys in map: %v", enc.Fields) |
| 355 | |
| 356 | assertCanBeReused(t, tt.field) |
| 357 | }) |
| 358 | } |
| 359 | } |
nothing calls this directly
no test coverage detected