MCPcopy
hub / github.com/pocketbase/pocketbase / TestNewApiErrorWithValidationData

Function TestNewApiErrorWithValidationData

tools/router/error_test.go:41–78  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

39}
40
41func TestNewApiErrorWithValidationData(t *testing.T) {
42 t.Parallel()
43
44 e := router.NewApiError(
45 300,
46 "message_test",
47 map[string]any{
48 "err1": errors.New("test error"), // should be normalized
49 "err2": validation.ErrRequired,
50 "err3": validation.Errors{
51 "err3.1": errors.New("test error"), // should be normalized
52 "err3.2": validation.ErrRequired,
53 "err3.3": validation.Errors{
54 "err3.3.1": validation.ErrRequired,
55 },
56 },
57 "err4": &mockSafeErrorItem{},
58 "err5": map[string]error{
59 "err5.1": validation.ErrRequired,
60 },
61 },
62 )
63
64 result, _ := json.Marshal(e)
65 expected := `{"data":{"err1":{"code":"validation_invalid_value","message":"Invalid value."},"err2":{"code":"validation_required","message":"Cannot be blank."},"err3":{"err3.1":{"code":"validation_invalid_value","message":"Invalid value."},"err3.2":{"code":"validation_required","message":"Cannot be blank."},"err3.3":{"err3.3.1":{"code":"validation_required","message":"Cannot be blank."}}},"err4":{"code":"mock_code","message":"Mock_error.","mock_resolve":123},"err5":{"err5.1":{"code":"validation_required","message":"Cannot be blank."}}},"message":"Message_test.","status":300}`
66
67 if string(result) != expected {
68 t.Errorf("Expected \n%v, \ngot \n%v", expected, string(result))
69 }
70
71 if e.Error() != "Message_test." {
72 t.Errorf("Expected %q, got %q", "Message_test.", e.Error())
73 }
74
75 if e.RawData() == nil {
76 t.Error("Expected non-nil rawData")
77 }
78}
79
80func TestNewNotFoundError(t *testing.T) {
81 t.Parallel()

Callers

nothing calls this directly

Calls 4

ErrorMethod · 0.95
RawDataMethod · 0.95
NewApiErrorFunction · 0.92
ErrorMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…