MCPcopy
hub / github.com/pocketbase/pocketbase / TestValidationErrors

Function TestValidationErrors

tests/validation_errors.go:12–32  ·  view source on GitHub ↗

TestValidationErrors checks whether the provided rawErrors are instance of [validation.Errors] and contains the expectedErrors keys.

(t *testing.T, rawErrors error, expectedErrors []string)

Source from the content-addressed store, hash-verified

10// TestValidationErrors checks whether the provided rawErrors are
11// instance of [validation.Errors] and contains the expectedErrors keys.
12func TestValidationErrors(t *testing.T, rawErrors error, expectedErrors []string) {
13 var errs validation.Errors
14
15 if rawErrors != nil && !errors.As(rawErrors, &errs) {
16 t.Fatalf("Failed to parse errors, expected to find validation.Errors, got %T\n%v", rawErrors, rawErrors)
17 }
18
19 if len(errs) != len(expectedErrors) {
20 keys := make([]string, 0, len(errs))
21 for k := range errs {
22 keys = append(keys, k)
23 }
24 t.Fatalf("Expected error keys \n%v\ngot\n%v\n%v", expectedErrors, keys, errs)
25 }
26
27 for _, k := range expectedErrors {
28 if _, ok := errs[k]; !ok {
29 t.Fatalf("Missing expected error key %q in %v", k, errs)
30 }
31 }
32}

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…