MCPcopy Create free account
hub / github.com/gotify/server / TestValidationError

Function TestValidationError

error/handler_test.go:56–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

54}
55
56func TestValidationError(t *testing.T) {
57 mode.Set(mode.TestDev)
58 rec := httptest.NewRecorder()
59 ctx, _ := gin.CreateTestContext(rec)
60 ctx.Request = httptest.NewRequest("GET", "/uri", nil)
61
62 assert.Error(t, ctx.Bind(&testValidate{Age: 150, Limit: 20}))
63 Handler()(ctx)
64
65 err := new(model.Error)
66 json.NewDecoder(rec.Body).Decode(err)
67 assert.Equal(t, 400, rec.Code)
68 assert.Equal(t, "Bad Request", err.Error)
69 assert.Equal(t, 400, err.ErrorCode)
70 assert.Contains(t, err.ErrorDescription, "Field 'username' is required")
71 assert.Contains(t, err.ErrorDescription, "Field 'mail' is not valid")
72 assert.Contains(t, err.ErrorDescription, "Field 'age' must be less or equal to 100")
73 assert.Contains(t, err.ErrorDescription, "Field 'limit' must be more or equal to 50")
74}
75
76func assertJSONResponse(t *testing.T, rec *httptest.ResponseRecorder, code int, json string) {
77 bytes, _ := io.ReadAll(rec.Body)

Callers

nothing calls this directly

Calls 3

SetFunction · 0.92
HandlerFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…