TestMarshalImportInputValue tests the marshalImportInputValue helper for correct JSON serialization of array and map types, including typed slices produced by goccy/go-yaml (e.g. []string instead of []any).
(t *testing.T)
| 751 | // JSON serialization of array and map types, including typed slices produced by |
| 752 | // goccy/go-yaml (e.g. []string instead of []any). |
| 753 | func TestMarshalImportInputValue(t *testing.T) { |
| 754 | tests := []struct { |
| 755 | name string |
| 756 | value any |
| 757 | want string |
| 758 | }{ |
| 759 | { |
| 760 | name: "string scalar", |
| 761 | value: "hello", |
| 762 | want: "hello", |
| 763 | }, |
| 764 | { |
| 765 | name: "int scalar", |
| 766 | value: 42, |
| 767 | want: "42", |
| 768 | }, |
| 769 | { |
| 770 | name: "bool scalar", |
| 771 | value: true, |
| 772 | want: "true", |
| 773 | }, |
| 774 | { |
| 775 | name: "[]any slice", |
| 776 | value: []any{"a", "b", "c"}, |
| 777 | want: `["a","b","c"]`, |
| 778 | }, |
| 779 | { |
| 780 | // goccy/go-yaml produces []string instead of []any for string arrays |
| 781 | name: "[]string typed slice (goccy/go-yaml output)", |
| 782 | value: []string{"microsoft/apm#main", "github/awesome-copilot/skills/foo"}, |
| 783 | want: `["microsoft/apm#main","github/awesome-copilot/skills/foo"]`, |
| 784 | }, |
| 785 | { |
| 786 | name: "[]int typed slice", |
| 787 | value: []int{1, 2, 3}, |
| 788 | want: `[1,2,3]`, |
| 789 | }, |
| 790 | { |
| 791 | name: "map[string]any", |
| 792 | value: map[string]any{"key": "val"}, |
| 793 | want: `{"key":"val"}`, |
| 794 | }, |
| 795 | { |
| 796 | name: "empty []string", |
| 797 | value: []string{}, |
| 798 | want: `[]`, |
| 799 | }, |
| 800 | { |
| 801 | name: "nil value", |
| 802 | value: nil, |
| 803 | want: "", |
| 804 | }, |
| 805 | } |
| 806 | |
| 807 | for _, tt := range tests { |
| 808 | t.Run(tt.name, func(t *testing.T) { |
| 809 | got := marshalImportInputValue(tt.value) |
| 810 | if got != tt.want { |
nothing calls this directly
no test coverage detected