MCPcopy
hub / github.com/pocketbase/pocketbase / testDefaultFieldIdValidation

Function testDefaultFieldIdValidation

core/field_test.go:73–122  ·  view source on GitHub ↗
(t *testing.T, fieldType string)

Source from the content-addressed store, hash-verified

71}
72
73func testDefaultFieldIdValidation(t *testing.T, fieldType string) {
74 app, _ := tests.NewTestApp()
75 defer app.Cleanup()
76
77 collection := core.NewBaseCollection("test_collection")
78
79 scenarios := []struct {
80 name string
81 field func() core.Field
82 expectError bool
83 }{
84 {
85 "empty value",
86 func() core.Field {
87 f := core.Fields[fieldType]()
88 return f
89 },
90 true,
91 },
92 {
93 "invalid length",
94 func() core.Field {
95 f := core.Fields[fieldType]()
96 f.SetId(strings.Repeat("a", 101))
97 return f
98 },
99 true,
100 },
101 {
102 "valid length",
103 func() core.Field {
104 f := core.Fields[fieldType]()
105 f.SetId(strings.Repeat("a", 100))
106 return f
107 },
108 false,
109 },
110 }
111
112 for _, s := range scenarios {
113 t.Run("[id] "+s.name, func(t *testing.T) {
114 errs, _ := s.field().ValidateSettings(context.Background(), app, collection).(validation.Errors)
115
116 hasErr := errs["id"] != nil
117 if hasErr != s.expectError {
118 t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, errs)
119 }
120 })
121 }
122}
123
124func testDefaultFieldNameValidation(t *testing.T, fieldType string) {
125 app, _ := tests.NewTestApp()

Calls 6

CleanupMethod · 0.95
NewTestAppFunction · 0.92
NewBaseCollectionFunction · 0.92
SetIdMethod · 0.65
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…