(t *testing.T)
| 780 | } |
| 781 | |
| 782 | func TestDecodeExpression(t *testing.T) { |
| 783 | tests := []struct { |
| 784 | Value cty.Value |
| 785 | Target interface{} |
| 786 | Want interface{} |
| 787 | DiagCount int |
| 788 | }{ |
| 789 | { |
| 790 | cty.StringVal("hello"), |
| 791 | "", |
| 792 | "hello", |
| 793 | 0, |
| 794 | }, |
| 795 | { |
| 796 | cty.StringVal("hello"), |
| 797 | cty.NilVal, |
| 798 | cty.StringVal("hello"), |
| 799 | 0, |
| 800 | }, |
| 801 | { |
| 802 | cty.NumberIntVal(2), |
| 803 | "", |
| 804 | "2", |
| 805 | 0, |
| 806 | }, |
| 807 | { |
| 808 | cty.StringVal("true"), |
| 809 | false, |
| 810 | true, |
| 811 | 0, |
| 812 | }, |
| 813 | { |
| 814 | cty.NullVal(cty.String), |
| 815 | "", |
| 816 | "", |
| 817 | 1, // null value is not allowed |
| 818 | }, |
| 819 | { |
| 820 | cty.UnknownVal(cty.String), |
| 821 | "", |
| 822 | "", |
| 823 | 1, // value must be known |
| 824 | }, |
| 825 | { |
| 826 | cty.ListVal([]cty.Value{cty.True}), |
| 827 | false, |
| 828 | false, |
| 829 | 1, // bool required |
| 830 | }, |
| 831 | } |
| 832 | |
| 833 | for i, test := range tests { |
| 834 | t.Run(fmt.Sprintf("%02d", i), func(t *testing.T) { |
| 835 | expr := &fixedExpression{test.Value} |
| 836 | |
| 837 | targetVal := reflect.New(reflect.TypeOf(test.Target)) |
| 838 | |
| 839 | diags := DecodeExpression(expr, nil, targetVal.Interface()) |
nothing calls this directly
no test coverage detected