TestNormalizeForJSONSchema_NestedMap verifies recursive normalization of maps.
(t *testing.T)
| 1440 | |
| 1441 | // TestNormalizeForJSONSchema_NestedMap verifies recursive normalization of maps. |
| 1442 | func TestNormalizeForJSONSchema_NestedMap(t *testing.T) { |
| 1443 | input := map[string]any{ |
| 1444 | "name": "test", |
| 1445 | "count": uint64(42), |
| 1446 | "offset": int64(-3), |
| 1447 | "enabled": true, |
| 1448 | "nested": map[string]any{ |
| 1449 | "port": uint64(8080), |
| 1450 | "label": "inner", |
| 1451 | }, |
| 1452 | } |
| 1453 | |
| 1454 | result := normalizeForJSONSchema(input) |
| 1455 | resultMap, ok := result.(map[string]any) |
| 1456 | if !ok { |
| 1457 | t.Fatalf("expected map[string]any, got %T", result) |
| 1458 | } |
| 1459 | |
| 1460 | if resultMap["name"] != "test" { |
| 1461 | t.Errorf("name: got %v, want test", resultMap["name"]) |
| 1462 | } |
| 1463 | if resultMap["count"] != float64(42) { |
| 1464 | t.Errorf("count: got %T(%v), want float64(42)", resultMap["count"], resultMap["count"]) |
| 1465 | } |
| 1466 | if resultMap["offset"] != float64(-3) { |
| 1467 | t.Errorf("offset: got %T(%v), want float64(-3)", resultMap["offset"], resultMap["offset"]) |
| 1468 | } |
| 1469 | if resultMap["enabled"] != true { |
| 1470 | t.Errorf("enabled: got %v, want true", resultMap["enabled"]) |
| 1471 | } |
| 1472 | |
| 1473 | nestedMap, ok := resultMap["nested"].(map[string]any) |
| 1474 | if !ok { |
| 1475 | t.Fatalf("nested: expected map[string]any, got %T", resultMap["nested"]) |
| 1476 | } |
| 1477 | if nestedMap["port"] != float64(8080) { |
| 1478 | t.Errorf("nested.port: got %T(%v), want float64(8080)", nestedMap["port"], nestedMap["port"]) |
| 1479 | } |
| 1480 | if nestedMap["label"] != "inner" { |
| 1481 | t.Errorf("nested.label: got %v, want inner", nestedMap["label"]) |
| 1482 | } |
| 1483 | |
| 1484 | // Verify the original input is NOT mutated |
| 1485 | if input["count"] != uint64(42) { |
| 1486 | t.Errorf("original input mutated: count is %T(%v), expected uint64(42)", input["count"], input["count"]) |
| 1487 | } |
| 1488 | } |
| 1489 | |
| 1490 | // TestNormalizeForJSONSchema_Slice verifies recursive normalization of slices. |
| 1491 | func TestNormalizeForJSONSchema_Slice(t *testing.T) { |
nothing calls this directly
no test coverage detected