MCPcopy
hub / github.com/pocketbase/pocketbase / TestNewBadRequestError

Function TestNewBadRequestError

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

Source from the content-addressed store, hash-verified

103}
104
105func TestNewBadRequestError(t *testing.T) {
106 t.Parallel()
107
108 scenarios := []struct {
109 message string
110 data any
111 expected string
112 }{
113 {"", nil, `{"data":{},"message":"Something went wrong while processing your request.","status":400}`},
114 {"demo", "rawData_test", `{"data":{},"message":"Demo.","status":400}`},
115 {"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"data":{"err1":{"code":"test_code","message":"Test_message."}},"message":"Demo.","status":400}`},
116 }
117
118 for i, s := range scenarios {
119 t.Run(strconv.Itoa(i), func(t *testing.T) {
120 e := router.NewBadRequestError(s.message, s.data)
121 result, _ := json.Marshal(e)
122
123 if str := string(result); str != s.expected {
124 t.Fatalf("Expected\n%v\ngot\n%v", s.expected, str)
125 }
126 })
127 }
128}
129
130func TestNewForbiddenError(t *testing.T) {
131 t.Parallel()

Callers

nothing calls this directly

Calls 2

NewBadRequestErrorFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…