(t *testing.T)
| 713 | } |
| 714 | |
| 715 | func TestConfigFromJSONErrors(t *testing.T) { |
| 716 | tcs := []struct { |
| 717 | name string |
| 718 | jsonIn string |
| 719 | wantErr string |
| 720 | }{ |
| 721 | { |
| 722 | name: "invalid json", |
| 723 | jsonIn: `{"name": `, |
| 724 | wantErr: "unexpected end of JSON input", |
| 725 | }, |
| 726 | { |
| 727 | name: "invalid variable json", |
| 728 | jsonIn: `{"variables": ["not-an-object"]}`, |
| 729 | wantErr: "cannot unmarshal string", |
| 730 | }, |
| 731 | { |
| 732 | name: "unsupported json type for TypeDesc", |
| 733 | jsonIn: `{"variables": [{"name": "x", "type": 123}]}`, |
| 734 | wantErr: "unsupported type description encoding", |
| 735 | }, |
| 736 | { |
| 737 | name: "invalid type specifier in TypeDesc", |
| 738 | jsonIn: `{"variables": [{"name": "x", "type": "list<"}]}`, |
| 739 | wantErr: "failed to parse type", |
| 740 | }, |
| 741 | { |
| 742 | name: "invalid structured TypeDesc", |
| 743 | jsonIn: `{"variables": [{"name": "x", "type": {"typeName": 123}}]}`, |
| 744 | wantErr: "cannot unmarshal number", |
| 745 | }, |
| 746 | { |
| 747 | name: "invalid validator json", |
| 748 | jsonIn: `{"validators": ["not-an-object"]}`, |
| 749 | wantErr: "cannot unmarshal string", |
| 750 | }, |
| 751 | { |
| 752 | name: "invalid context variable json", |
| 753 | jsonIn: `{"contextVariable": "not-an-object"}`, |
| 754 | wantErr: "cannot unmarshal string", |
| 755 | }, |
| 756 | { |
| 757 | name: "unsupported json type for Overload", |
| 758 | jsonIn: `{"functions": [{"name": "f", "overloads": [123]}]}`, |
| 759 | wantErr: "unsupported overload encoding", |
| 760 | }, |
| 761 | { |
| 762 | name: "invalid structured Overload", |
| 763 | jsonIn: `{"functions": [{"name": "f", "overloads": [{"id": 123}]}]}`, |
| 764 | wantErr: "cannot unmarshal number", |
| 765 | }, |
| 766 | } |
| 767 | |
| 768 | for _, tc := range tcs { |
| 769 | t.Run(tc.name, func(t *testing.T) { |
| 770 | _, err := ConfigFromJSON([]byte(tc.jsonIn)) |
| 771 | if err == nil { |
| 772 | t.Fatalf("ConfigFromJSON(%q) = nil, wanted error containing %q", tc.jsonIn, tc.wantErr) |
nothing calls this directly
no test coverage detected