@@ -86,6 +86,18 @@ func TestAtLeastSumOfValidator(t *testing.T) {
86
86
"two" : tftypes .NewValue (tftypes .Number , nil ),
87
87
},
88
88
},
89
+ "valid integer as Int64 returns error when all attributes to sum are null" : {
90
+ val : types.Int64 {Value : - 1 },
91
+ attributesToSumPaths : []* tftypes.AttributePath {
92
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
93
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
94
+ },
95
+ requestConfigRaw : map [string ]tftypes.Value {
96
+ "one" : tftypes .NewValue (tftypes .Number , nil ),
97
+ "two" : tftypes .NewValue (tftypes .Number , nil ),
98
+ },
99
+ expectError : true ,
100
+ },
89
101
"valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown" : {
90
102
val : types.Int64 {Value : 10 },
91
103
attributesToSumPaths : []* tftypes.AttributePath {
@@ -108,6 +120,29 @@ func TestAtLeastSumOfValidator(t *testing.T) {
108
120
"two" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
109
121
},
110
122
},
123
+ "valid integer as Int64 does not return error when all attributes to sum are unknown" : {
124
+ val : types.Int64 {Value : - 1 },
125
+ attributesToSumPaths : []* tftypes.AttributePath {
126
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
127
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
128
+ },
129
+ requestConfigRaw : map [string ]tftypes.Value {
130
+ "one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
131
+ "two" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
132
+ },
133
+ },
134
+ "error when attribute to sum is not Number" : {
135
+ val : types.Int64 {Value : 9 },
136
+ attributesToSumPaths : []* tftypes.AttributePath {
137
+ tftypes .NewAttributePath ().WithAttributeName ("one" ),
138
+ tftypes .NewAttributePath ().WithAttributeName ("two" ),
139
+ },
140
+ requestConfigRaw : map [string ]tftypes.Value {
141
+ "one" : tftypes .NewValue (tftypes .Bool , true ),
142
+ "two" : tftypes .NewValue (tftypes .Number , 9 ),
143
+ },
144
+ expectError : true ,
145
+ },
111
146
}
112
147
113
148
for name , test := range tests {
@@ -130,7 +165,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
130
165
131
166
response := tfsdk.ValidateAttributeResponse {}
132
167
133
- AtLeastSumOf (test .attributesToSumPaths ).Validate (context .Background (), request , & response )
168
+ AtLeastSumOf (test .attributesToSumPaths ... ).Validate (context .Background (), request , & response )
134
169
135
170
if ! response .Diagnostics .HasError () && test .expectError {
136
171
t .Fatal ("expected error, got no error" )
0 commit comments