MCPcopy
hub / github.com/pocketbase/pocketbase / testDefaultFieldHelpValidation

Function testDefaultFieldHelpValidation

core/field_test.go:265–320  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func testDefaultFieldHelpValidation[T any](t *testing.T) {
266 app, _ := tests.NewTestApp()
267 defer app.Cleanup()
268
269 collection := core.NewBaseCollection("test_collection")
270
271 scenarios := []struct {
272 name string
273 json string
274 expectError bool
275 }{
276 {
277 "empty value",
278 `{}`,
279 false,
280 },
281 {
282 "< max limit",
283 `{"help":"abc"}`,
284 false,
285 },
286 {
287 "= max limit",
288 `{"help":"` + strings.Repeat("a", 300) + `"}`,
289 false,
290 },
291 {
292 "> max limit",
293 `{"help":"` + strings.Repeat("a", 301) + `"}`,
294 true,
295 },
296 }
297
298 for _, s := range scenarios {
299 t.Run("[help] "+s.name, func(t *testing.T) {
300 var zeroField T
301
302 field, ok := reflect.New(reflect.TypeOf(zeroField)).Interface().(core.Field)
303 if !ok {
304 t.Fatalf("Expected core.Field instance, got %T", zeroField)
305 }
306
307 err := json.Unmarshal([]byte(s.json), &field)
308 if err != nil {
309 t.Fatal(err)
310 }
311
312 errs, _ := field.ValidateSettings(context.Background(), app, collection).(validation.Errors)
313
314 hasErr := errs["help"] != nil
315 if hasErr != s.expectError {
316 t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, errs)
317 }
318 })
319 }
320}

Callers

nothing calls this directly

Calls 5

CleanupMethod · 0.95
NewTestAppFunction · 0.92
NewBaseCollectionFunction · 0.92
ValidateSettingsMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…