(t *testing.T)
| 1173 | } |
| 1174 | |
| 1175 | func 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 | |
| 1217 | func TestRecordDBExport(t *testing.T) { |
| 1218 | t.Parallel() |
nothing calls this directly
no test coverage detected
searching dependent graphs…