MCPcopy
hub / github.com/pocketbase/pocketbase / TestNewForbiddenError

Function TestNewForbiddenError

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

Source from the content-addressed store, hash-verified

128}
129
130func TestNewForbiddenError(t *testing.T) {
131 t.Parallel()
132
133 scenarios := []struct {
134 message string
135 data any
136 expected string
137 }{
138 {"", nil, `{"data":{},"message":"You are not allowed to perform this request.","status":403}`},
139 {"demo", "rawData_test", `{"data":{},"message":"Demo.","status":403}`},
140 {"demo", validation.Errors{"err1": validation.NewError("test_code", "test_message")}, `{"data":{"err1":{"code":"test_code","message":"Test_message."}},"message":"Demo.","status":403}`},
141 }
142
143 for i, s := range scenarios {
144 t.Run(strconv.Itoa(i), func(t *testing.T) {
145 e := router.NewForbiddenError(s.message, s.data)
146 result, _ := json.Marshal(e)
147
148 if str := string(result); str != s.expected {
149 t.Fatalf("Expected\n%v\ngot\n%v", s.expected, str)
150 }
151 })
152 }
153}
154
155func TestNewUnauthorizedError(t *testing.T) {
156 t.Parallel()

Callers

nothing calls this directly

Calls 2

NewForbiddenErrorFunction · 0.92
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…