(t *testing.T)
| 627 | } |
| 628 | |
| 629 | func TestFileFieldFindGetter(t *testing.T) { |
| 630 | app, _ := tests.NewTestApp() |
| 631 | defer app.Cleanup() |
| 632 | |
| 633 | f1, err := filesystem.NewFileFromBytes([]byte("test"), "f1") |
| 634 | if err != nil { |
| 635 | t.Fatal(err) |
| 636 | } |
| 637 | f1.Name = "f1" |
| 638 | |
| 639 | f2, err := filesystem.NewFileFromBytes([]byte("test"), "f2") |
| 640 | if err != nil { |
| 641 | t.Fatal(err) |
| 642 | } |
| 643 | f2.Name = "f2" |
| 644 | |
| 645 | record, err := app.FindRecordById("demo3", "lcl9d87w22ml6jy") |
| 646 | if err != nil { |
| 647 | t.Fatal(err) |
| 648 | } |
| 649 | record.Set("files+", []any{f1, f2}) |
| 650 | record.Set("files-", "test_FLurQTgrY8.txt") |
| 651 | |
| 652 | field, ok := record.Collection().Fields.GetByName("files").(*core.FileField) |
| 653 | if !ok { |
| 654 | t.Fatalf("Expected *core.FileField, got %T", record.Collection().Fields.GetByName("files")) |
| 655 | } |
| 656 | |
| 657 | scenarios := []struct { |
| 658 | name string |
| 659 | key string |
| 660 | hasGetter bool |
| 661 | expected string |
| 662 | }{ |
| 663 | { |
| 664 | "no match", |
| 665 | "example", |
| 666 | false, |
| 667 | "", |
| 668 | }, |
| 669 | { |
| 670 | "exact match", |
| 671 | field.GetName(), |
| 672 | true, |
| 673 | `["300_UhLKX91HVb.png",{"name":"f1","originalName":"f1","size":4},{"name":"f2","originalName":"f2","size":4}]`, |
| 674 | }, |
| 675 | { |
| 676 | "unsaved", |
| 677 | field.GetName() + ":unsaved", |
| 678 | true, |
| 679 | `[{"name":"f1","originalName":"f1","size":4},{"name":"f2","originalName":"f2","size":4}]`, |
| 680 | }, |
| 681 | } |
| 682 | |
| 683 | for _, s := range scenarios { |
| 684 | t.Run(s.name, func(t *testing.T) { |
| 685 | getter := field.FindGetter(s.key) |
| 686 |
nothing calls this directly
no test coverage detected
searching dependent graphs…