@@ -15,10 +15,10 @@ func TestAtLeastSumOfValidator(t *testing.T) {
15
15
t .Parallel ()
16
16
17
17
type testCase struct {
18
- val attr.Value
19
- attributesToSumPaths [] path.Path
20
- requestConfigRaw map [string ]tftypes.Value
21
- expectError bool
18
+ val attr.Value
19
+ attributesToSumExpressions path.Expressions
20
+ requestConfigRaw map [string ]tftypes.Value
21
+ expectError bool
22
22
}
23
23
tests := map [string ]testCase {
24
24
"not an Int64" : {
@@ -33,9 +33,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
33
33
},
34
34
"valid integer as Int64 less than sum of attributes" : {
35
35
val : types.Int64 {Value : 10 },
36
- attributesToSumPaths : [] path.Path {
37
- path .Root ("one" ),
38
- path .Root ("two" ),
36
+ attributesToSumExpressions : path.Expressions {
37
+ path .MatchRoot ("one" ),
38
+ path .MatchRoot ("two" ),
39
39
},
40
40
requestConfigRaw : map [string ]tftypes.Value {
41
41
"one" : tftypes .NewValue (tftypes .Number , 15 ),
@@ -45,9 +45,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
45
45
},
46
46
"valid integer as Int64 equal to sum of attributes" : {
47
47
val : types.Int64 {Value : 10 },
48
- attributesToSumPaths : [] path.Path {
49
- path .Root ("one" ),
50
- path .Root ("two" ),
48
+ attributesToSumExpressions : path.Expressions {
49
+ path .MatchRoot ("one" ),
50
+ path .MatchRoot ("two" ),
51
51
},
52
52
requestConfigRaw : map [string ]tftypes.Value {
53
53
"one" : tftypes .NewValue (tftypes .Number , 5 ),
@@ -56,9 +56,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
56
56
},
57
57
"valid integer as Int64 greater than sum of attributes" : {
58
58
val : types.Int64 {Value : 10 },
59
- attributesToSumPaths : [] path.Path {
60
- path .Root ("one" ),
61
- path .Root ("two" ),
59
+ attributesToSumExpressions : path.Expressions {
60
+ path .MatchRoot ("one" ),
61
+ path .MatchRoot ("two" ),
62
62
},
63
63
requestConfigRaw : map [string ]tftypes.Value {
64
64
"one" : tftypes .NewValue (tftypes .Number , 4 ),
@@ -67,9 +67,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
67
67
},
68
68
"valid integer as Int64 greater than sum of attributes, when one summed attribute is null" : {
69
69
val : types.Int64 {Value : 10 },
70
- attributesToSumPaths : [] path.Path {
71
- path .Root ("one" ),
72
- path .Root ("two" ),
70
+ attributesToSumExpressions : path.Expressions {
71
+ path .MatchRoot ("one" ),
72
+ path .MatchRoot ("two" ),
73
73
},
74
74
requestConfigRaw : map [string ]tftypes.Value {
75
75
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -78,9 +78,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
78
78
},
79
79
"valid integer as Int64 does not return error when all attributes are null" : {
80
80
val : types.Int64 {Null : true },
81
- attributesToSumPaths : [] path.Path {
82
- path .Root ("one" ),
83
- path .Root ("two" ),
81
+ attributesToSumExpressions : path.Expressions {
82
+ path .MatchRoot ("one" ),
83
+ path .MatchRoot ("two" ),
84
84
},
85
85
requestConfigRaw : map [string ]tftypes.Value {
86
86
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -89,9 +89,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
89
89
},
90
90
"valid integer as Int64 returns error when all attributes to sum are null" : {
91
91
val : types.Int64 {Value : - 1 },
92
- attributesToSumPaths : [] path.Path {
93
- path .Root ("one" ),
94
- path .Root ("two" ),
92
+ attributesToSumExpressions : path.Expressions {
93
+ path .MatchRoot ("one" ),
94
+ path .MatchRoot ("two" ),
95
95
},
96
96
requestConfigRaw : map [string ]tftypes.Value {
97
97
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -101,9 +101,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
101
101
},
102
102
"valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown" : {
103
103
val : types.Int64 {Value : 10 },
104
- attributesToSumPaths : [] path.Path {
105
- path .Root ("one" ),
106
- path .Root ("two" ),
104
+ attributesToSumExpressions : path.Expressions {
105
+ path .MatchRoot ("one" ),
106
+ path .MatchRoot ("two" ),
107
107
},
108
108
requestConfigRaw : map [string ]tftypes.Value {
109
109
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -112,9 +112,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
112
112
},
113
113
"valid integer as Int64 does not return error when all attributes are unknown" : {
114
114
val : types.Int64 {Unknown : true },
115
- attributesToSumPaths : [] path.Path {
116
- path .Root ("one" ),
117
- path .Root ("two" ),
115
+ attributesToSumExpressions : path.Expressions {
116
+ path .MatchRoot ("one" ),
117
+ path .MatchRoot ("two" ),
118
118
},
119
119
requestConfigRaw : map [string ]tftypes.Value {
120
120
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -123,9 +123,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
123
123
},
124
124
"valid integer as Int64 does not return error when all attributes to sum are unknown" : {
125
125
val : types.Int64 {Value : - 1 },
126
- attributesToSumPaths : [] path.Path {
127
- path .Root ("one" ),
128
- path .Root ("two" ),
126
+ attributesToSumExpressions : path.Expressions {
127
+ path .MatchRoot ("one" ),
128
+ path .MatchRoot ("two" ),
129
129
},
130
130
requestConfigRaw : map [string ]tftypes.Value {
131
131
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -134,9 +134,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
134
134
},
135
135
"error when attribute to sum is not Number" : {
136
136
val : types.Int64 {Value : 9 },
137
- attributesToSumPaths : [] path.Path {
138
- path .Root ("one" ),
139
- path .Root ("two" ),
137
+ attributesToSumExpressions : path.Expressions {
138
+ path .MatchRoot ("one" ),
139
+ path .MatchRoot ("two" ),
140
140
},
141
141
requestConfigRaw : map [string ]tftypes.Value {
142
142
"one" : tftypes .NewValue (tftypes .Bool , true ),
@@ -150,8 +150,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
150
150
name , test := name , test
151
151
t .Run (name , func (t * testing.T ) {
152
152
request := tfsdk.ValidateAttributeRequest {
153
- AttributePath : path .Root ("test" ),
154
- AttributeConfig : test .val ,
153
+ AttributePath : path .Root ("test" ),
154
+ AttributePathExpression : path .MatchRoot ("test" ),
155
+ AttributeConfig : test .val ,
155
156
Config : tfsdk.Config {
156
157
Raw : tftypes .NewValue (tftypes.Object {}, test .requestConfigRaw ),
157
158
Schema : tfsdk.Schema {
@@ -166,7 +167,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
166
167
167
168
response := tfsdk.ValidateAttributeResponse {}
168
169
169
- AtLeastSumOf (test .attributesToSumPaths ... ).Validate (context .Background (), request , & response )
170
+ AtLeastSumOf (test .attributesToSumExpressions ... ).Validate (context .Background (), request , & response )
170
171
171
172
if ! response .Diagnostics .HasError () && test .expectError {
172
173
t .Fatal ("expected error, got no error" )
0 commit comments