@@ -86,6 +86,18 @@ func TestAtLeastSumOfValidator(t *testing.T) {
8686 "two" : tftypes .NewValue (tftypes .Number , nil ),
8787 },
8888 },
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+ },
89101 "valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown" : {
90102 val : types.Int64 {Value : 10 },
91103 attributesToSumPaths : []* tftypes.AttributePath {
@@ -108,6 +120,29 @@ func TestAtLeastSumOfValidator(t *testing.T) {
108120 "two" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
109121 },
110122 },
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+ },
111146 }
112147
113148 for name , test := range tests {
@@ -130,7 +165,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
130165
131166 response := tfsdk.ValidateAttributeResponse {}
132167
133- AtLeastSumOf (test .attributesToSumPaths ).Validate (context .Background (), request , & response )
168+ AtLeastSumOf (test .attributesToSumPaths ... ).Validate (context .Background (), request , & response )
134169
135170 if ! response .Diagnostics .HasError () && test .expectError {
136171 t .Fatal ("expected error, got no error" )
0 commit comments