(t *testing.T)
| 1442 | } |
| 1443 | |
| 1444 | func TestValidate(t *testing.T) { |
| 1445 | pb := huma.NewPathBuffer([]byte(""), 0) |
| 1446 | res := &huma.ValidateResult{} |
| 1447 | |
| 1448 | for _, test := range validateTests { |
| 1449 | t.Run(test.name, func(t *testing.T) { |
| 1450 | if test.before != nil { |
| 1451 | test.before() |
| 1452 | } |
| 1453 | if test.cleanup != nil { |
| 1454 | defer test.cleanup() |
| 1455 | } |
| 1456 | |
| 1457 | registry := huma.NewMapRegistry("#/components/schemas/", huma.DefaultSchemaNamer) |
| 1458 | |
| 1459 | var s *huma.Schema |
| 1460 | if test.panic != "" { |
| 1461 | assert.Panics(t, func() { |
| 1462 | registry.Schema(test.typ, true, "TestInput") |
| 1463 | }) |
| 1464 | return |
| 1465 | } |
| 1466 | |
| 1467 | if test.s != nil { |
| 1468 | s = test.s |
| 1469 | s.PrecomputeMessages() |
| 1470 | } else { |
| 1471 | s = registry.Schema(test.typ, true, "TestInput") |
| 1472 | } |
| 1473 | |
| 1474 | pb.Reset() |
| 1475 | res.Reset() |
| 1476 | |
| 1477 | huma.Validate(registry, s, pb, test.mode, test.input, res) |
| 1478 | |
| 1479 | assert.Len(t, res.Errors, len(test.errs)) |
| 1480 | if len(test.errs) > 0 { |
| 1481 | errs := mapTo(res.Errors, func(e error) string { |
| 1482 | return e.(*huma.ErrorDetail).Message |
| 1483 | }) |
| 1484 | schemaJSON, _ := json.MarshalIndent(registry.Map(), "", " ") |
| 1485 | for _, err := range test.errs { |
| 1486 | assert.Contains(t, errs, err, string(schemaJSON)) |
| 1487 | } |
| 1488 | } else { |
| 1489 | assert.Empty(t, res.Errors) |
| 1490 | } |
| 1491 | }) |
| 1492 | } |
| 1493 | } |
| 1494 | |
| 1495 | func TestValidateCustomFormatter(t *testing.T) { |
| 1496 | originalFormatter := huma.ErrorFormatter |
nothing calls this directly
no test coverage detected
searching dependent graphs…