@@ -16,7 +16,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
16
16
type testCase struct {
17
17
val attr.Value
18
18
attributesToSumPaths []* tftypes.AttributePath
19
- requestConfigRaw map [string ]tftypes .Value
19
+ requestConfigRaw map [string ]attr .Value
20
20
expectError bool
21
21
}
22
22
tests := map [string ]testCase {
@@ -36,9 +36,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
36
36
tftypes .NewAttributePath ().WithAttributeName ("one" ),
37
37
tftypes .NewAttributePath ().WithAttributeName ("two" ),
38
38
},
39
- requestConfigRaw : map [string ]tftypes .Value {
40
- "one" : tftypes . NewValue ( tftypes . Number , 15 ) ,
41
- "two" : tftypes . NewValue ( tftypes . Number , 15 ) ,
39
+ requestConfigRaw : map [string ]attr .Value {
40
+ "one" : types. Int64 { Value : 15 } ,
41
+ "two" : types. Int64 { Value : 15 } ,
42
42
},
43
43
expectError : true ,
44
44
},
@@ -48,9 +48,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
48
48
tftypes .NewAttributePath ().WithAttributeName ("one" ),
49
49
tftypes .NewAttributePath ().WithAttributeName ("two" ),
50
50
},
51
- requestConfigRaw : map [string ]tftypes .Value {
52
- "one" : tftypes . NewValue ( tftypes . Number , 5 ) ,
53
- "two" : tftypes . NewValue ( tftypes . Number , 5 ) ,
51
+ requestConfigRaw : map [string ]attr .Value {
52
+ "one" : types. Int64 { Value : 5 } ,
53
+ "two" : types. Int64 { Value : 5 } ,
54
54
},
55
55
},
56
56
"valid integer as Int64 greater than sum of attributes" : {
@@ -59,21 +59,76 @@ func TestAtLeastSumOfValidator(t *testing.T) {
59
59
tftypes .NewAttributePath ().WithAttributeName ("one" ),
60
60
tftypes .NewAttributePath ().WithAttributeName ("two" ),
61
61
},
62
- requestConfigRaw : map [string ]tftypes.Value {
63
- "one" : tftypes .NewValue (tftypes .Number , 4 ),
64
- "two" : tftypes .NewValue (tftypes .Number , 4 ),
62
+ requestConfigRaw : map [string ]attr.Value {
63
+ "one" : types.Int64 {Value : 4 },
64
+ "two" : types.Int64 {Value : 4 },
65
+ },
66
+ },
67
+ "valid integer as Int64 greater than sum of attributes, when one summed attribute is null" : {
68
+ val : types.Int64 {Value : 10 },
69
+ attributesToSumPaths : []* tftypes.AttributePath {
70
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
71
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
72
+ },
73
+ requestConfigRaw : map [string ]attr.Value {
74
+ "one" : types.Int64 {Null : true },
75
+ "two" : types.Int64 {Value : 9 },
76
+ },
77
+ },
78
+ "valid integer as Int64 does not return error when all attributes are null" : {
79
+ val : types.Int64 {Null : true },
80
+ attributesToSumPaths : []* tftypes.AttributePath {
81
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
82
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
83
+ },
84
+ requestConfigRaw : map [string ]attr.Value {
85
+ "one" : types.Int64 {Null : true },
86
+ "two" : types.Int64 {Null : true },
87
+ },
88
+ },
89
+ "valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown" : {
90
+ val : types.Int64 {Value : 10 },
91
+ attributesToSumPaths : []* tftypes.AttributePath {
92
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
93
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
94
+ },
95
+ requestConfigRaw : map [string ]attr.Value {
96
+ "one" : types.Int64 {Unknown : true },
97
+ "two" : types.Int64 {Value : 9 },
98
+ },
99
+ },
100
+ "valid integer as Int64 does not return error when all attributes are unknown" : {
101
+ val : types.Int64 {Unknown : true },
102
+ attributesToSumPaths : []* tftypes.AttributePath {
103
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
104
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
105
+ },
106
+ requestConfigRaw : map [string ]attr.Value {
107
+ "one" : types.Int64 {Unknown : true },
108
+ "two" : types.Int64 {Unknown : true },
65
109
},
66
110
},
67
111
}
68
112
69
113
for name , test := range tests {
70
114
name , test := name , test
71
115
t .Run (name , func (t * testing.T ) {
116
+ reqConf := make (map [string ]tftypes.Value , len (test .requestConfigRaw ))
117
+
118
+ for k , v := range test .requestConfigRaw {
119
+ val , err := v .ToTerraformValue (context .Background ())
120
+ if err != nil {
121
+ t .Fatalf ("could not attr.Value at key:%s to tftypes.Value" , k )
122
+ }
123
+
124
+ reqConf [k ] = val
125
+ }
126
+
72
127
request := tfsdk.ValidateAttributeRequest {
73
128
AttributePath : tftypes .NewAttributePath ().WithAttributeName ("test" ),
74
129
AttributeConfig : test .val ,
75
130
Config : tfsdk.Config {
76
- Raw : tftypes .NewValue (tftypes.Object {}, test . requestConfigRaw ),
131
+ Raw : tftypes .NewValue (tftypes.Object {}, reqConf ),
77
132
Schema : tfsdk.Schema {
78
133
Attributes : map [string ]tfsdk.Attribute {
79
134
"test" : {Type : types .Int64Type },
0 commit comments