(t *testing.T)
| 704 | } |
| 705 | |
| 706 | func TestRecordSetGet(t *testing.T) { |
| 707 | t.Parallel() |
| 708 | |
| 709 | f1 := &mockField{} |
| 710 | f1.Name = "mock1" |
| 711 | |
| 712 | f2 := &mockField{} |
| 713 | f2.Name = "mock2" |
| 714 | |
| 715 | f3 := &mockField{} |
| 716 | f3.Name = "mock3" |
| 717 | |
| 718 | collection := core.NewBaseCollection("test") |
| 719 | collection.Fields.Add(&core.TextField{Name: "text1"}) |
| 720 | collection.Fields.Add(&core.TextField{Name: "text2"}) |
| 721 | collection.Fields.Add(f1) |
| 722 | collection.Fields.Add(f2) |
| 723 | collection.Fields.Add(f3) |
| 724 | |
| 725 | record := core.NewRecord(collection) |
| 726 | record.Set("text1", 123) // should be converted to string using the ScanValue fallback |
| 727 | record.SetRaw("text2", 456) |
| 728 | record.Set("mock1", 1) // should be converted to string using the setter |
| 729 | record.SetRaw("mock2", 1) |
| 730 | record.Set("mock3:test", "abc") |
| 731 | record.Set("unknown", 789) |
| 732 | |
| 733 | t.Run("GetRaw", func(t *testing.T) { |
| 734 | expected := map[string]any{ |
| 735 | "text1": "123", |
| 736 | "text2": 456, |
| 737 | "mock1": "1", |
| 738 | "mock2": 1, |
| 739 | "mock3": "modifier_set", |
| 740 | "mock3:test": nil, |
| 741 | "unknown": 789, |
| 742 | } |
| 743 | |
| 744 | for k, v := range expected { |
| 745 | raw := record.GetRaw(k) |
| 746 | if raw != v { |
| 747 | t.Errorf("Expected %q to be %v, got %v", k, v, raw) |
| 748 | } |
| 749 | } |
| 750 | }) |
| 751 | |
| 752 | t.Run("Get", func(t *testing.T) { |
| 753 | expected := map[string]any{ |
| 754 | "text1": "123", |
| 755 | "text2": 456, |
| 756 | "mock1": "1", |
| 757 | "mock2": 1, |
| 758 | "mock3": "modifier_set", |
| 759 | "mock3:test": "modifier_get", |
| 760 | "unknown": 789, |
| 761 | } |
| 762 | |
| 763 | for k, v := range expected { |
nothing calls this directly
no test coverage detected
searching dependent graphs…