MCPcopy Index your code
hub / github.com/pocketbase/pocketbase / TestRecordFindFileFieldByFile

Function TestRecordFindFileFieldByFile

core/record_model_test.go:1175–1215  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1173}
1174
1175func TestRecordFindFileFieldByFile(t *testing.T) {
1176 t.Parallel()
1177
1178 collection := core.NewBaseCollection("test")
1179 collection.Fields.Add(
1180 &core.TextField{Name: "field1"},
1181 &core.FileField{Name: "field2", MaxSelect: 1, MaxSize: 1},
1182 &core.FileField{Name: "field3", MaxSelect: 2, MaxSize: 1},
1183 )
1184
1185 m := core.NewRecord(collection)
1186 m.Set("field1", "test")
1187 m.Set("field2", "test.png")
1188 m.Set("field3", []string{"test1.png", "test2.png"})
1189
1190 scenarios := []struct {
1191 filename string
1192 expectField string
1193 }{
1194 {"", ""},
1195 {"test", ""},
1196 {"test2", ""},
1197 {"test.png", "field2"},
1198 {"test2.png", "field3"},
1199 }
1200
1201 for i, s := range scenarios {
1202 t.Run(fmt.Sprintf("%d_%#v", i, s.filename), func(t *testing.T) {
1203 result := m.FindFileFieldByFile(s.filename)
1204
1205 var fieldName string
1206 if result != nil {
1207 fieldName = result.Name
1208 }
1209
1210 if s.expectField != fieldName {
1211 t.Fatalf("Expected field %v, got %v", s.expectField, result)
1212 }
1213 })
1214 }
1215}
1216
1217func TestRecordDBExport(t *testing.T) {
1218 t.Parallel()

Callers

nothing calls this directly

Calls 6

SetMethod · 0.95
FindFileFieldByFileMethod · 0.95
NewBaseCollectionFunction · 0.92
NewRecordFunction · 0.92
AddMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…