feat(05-05): accept boolean validation token
- Treat Laravel boolean as a type-check no-op in lagoon.Validate - Settings.search_use_typesense uses this rule string
This commit is contained in:
@@ -85,6 +85,8 @@ func validateField(ctx context.Context, tx *gorm.DB, model any, field, rule stri
|
||||
tags = append(tags, oneofTag(strings.Split(arg, ",")))
|
||||
case "unique":
|
||||
uniqueTable = arg
|
||||
case "boolean":
|
||||
// Go's bool field type already enforces this; treat as a type-check no-op.
|
||||
default:
|
||||
return nil, fmt.Errorf("lagoon: unrecognized validation rule %q", tok)
|
||||
}
|
||||
|
||||
@@ -73,6 +73,19 @@ func TestValidateMoneyRange(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateBooleanNoop(t *testing.T) {
|
||||
rules := map[string]string{"search_use_typesense": "boolean"}
|
||||
for _, v := range []any{true, false} {
|
||||
errs, err := Validate(t.Context(), nil, nil, rules, map[string]any{"search_use_typesense": v}, nil)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(errs) != 0 {
|
||||
t.Fatalf("boolean %v = %v", v, errs)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateUnrecognizedRule(t *testing.T) {
|
||||
_, err := Validate(t.Context(), nil, nil, map[string]string{"name": "required|nope"}, map[string]any{"name": "x"}, nil)
|
||||
if err == nil || !strings.Contains(err.Error(), "nope") {
|
||||
|
||||
Reference in New Issue
Block a user