5
5
"testing"
6
6
7
7
"github.com/hashicorp/terraform-plugin-framework/attr"
8
+ "github.com/hashicorp/terraform-plugin-framework/path"
8
9
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
9
10
"github.com/hashicorp/terraform-plugin-framework/types"
10
11
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -15,7 +16,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
15
16
16
17
type testCase struct {
17
18
val attr.Value
18
- attributesToSumPaths []* tftypes. AttributePath
19
+ attributesToSumPaths []path. Path
19
20
requestConfigRaw map [string ]tftypes.Value
20
21
expectError bool
21
22
}
@@ -32,9 +33,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
32
33
},
33
34
"valid integer as Int64 less than sum of attributes" : {
34
35
val : types.Int64 {Value : 10 },
35
- attributesToSumPaths : []* tftypes. AttributePath {
36
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
37
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
36
+ attributesToSumPaths : []path. Path {
37
+ path . Root ("one" ),
38
+ path . Root ("two" ),
38
39
},
39
40
requestConfigRaw : map [string ]tftypes.Value {
40
41
"one" : tftypes .NewValue (tftypes .Number , 15 ),
@@ -44,9 +45,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
44
45
},
45
46
"valid integer as Int64 equal to sum of attributes" : {
46
47
val : types.Int64 {Value : 10 },
47
- attributesToSumPaths : []* tftypes. AttributePath {
48
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
49
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
48
+ attributesToSumPaths : []path. Path {
49
+ path . Root ("one" ),
50
+ path . Root ("two" ),
50
51
},
51
52
requestConfigRaw : map [string ]tftypes.Value {
52
53
"one" : tftypes .NewValue (tftypes .Number , 5 ),
@@ -55,9 +56,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
55
56
},
56
57
"valid integer as Int64 greater than sum of attributes" : {
57
58
val : types.Int64 {Value : 10 },
58
- attributesToSumPaths : []* tftypes. AttributePath {
59
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
60
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
59
+ attributesToSumPaths : []path. Path {
60
+ path . Root ("one" ),
61
+ path . Root ("two" ),
61
62
},
62
63
requestConfigRaw : map [string ]tftypes.Value {
63
64
"one" : tftypes .NewValue (tftypes .Number , 4 ),
@@ -66,9 +67,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
66
67
},
67
68
"valid integer as Int64 greater than sum of attributes, when one summed attribute is null" : {
68
69
val : types.Int64 {Value : 10 },
69
- attributesToSumPaths : []* tftypes. AttributePath {
70
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
71
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
70
+ attributesToSumPaths : []path. Path {
71
+ path . Root ("one" ),
72
+ path . Root ("two" ),
72
73
},
73
74
requestConfigRaw : map [string ]tftypes.Value {
74
75
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -77,9 +78,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
77
78
},
78
79
"valid integer as Int64 does not return error when all attributes are null" : {
79
80
val : types.Int64 {Null : true },
80
- attributesToSumPaths : []* tftypes. AttributePath {
81
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
82
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
81
+ attributesToSumPaths : []path. Path {
82
+ path . Root ("one" ),
83
+ path . Root ("two" ),
83
84
},
84
85
requestConfigRaw : map [string ]tftypes.Value {
85
86
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -88,9 +89,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
88
89
},
89
90
"valid integer as Int64 returns error when all attributes to sum are null" : {
90
91
val : types.Int64 {Value : - 1 },
91
- attributesToSumPaths : []* tftypes. AttributePath {
92
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
93
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
92
+ attributesToSumPaths : []path. Path {
93
+ path . Root ("one" ),
94
+ path . Root ("two" ),
94
95
},
95
96
requestConfigRaw : map [string ]tftypes.Value {
96
97
"one" : tftypes .NewValue (tftypes .Number , nil ),
@@ -100,9 +101,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
100
101
},
101
102
"valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown" : {
102
103
val : types.Int64 {Value : 10 },
103
- attributesToSumPaths : []* tftypes. AttributePath {
104
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
105
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
104
+ attributesToSumPaths : []path. Path {
105
+ path . Root ("one" ),
106
+ path . Root ("two" ),
106
107
},
107
108
requestConfigRaw : map [string ]tftypes.Value {
108
109
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -111,9 +112,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
111
112
},
112
113
"valid integer as Int64 does not return error when all attributes are unknown" : {
113
114
val : types.Int64 {Unknown : true },
114
- attributesToSumPaths : []* tftypes. AttributePath {
115
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
116
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
115
+ attributesToSumPaths : []path. Path {
116
+ path . Root ("one" ),
117
+ path . Root ("two" ),
117
118
},
118
119
requestConfigRaw : map [string ]tftypes.Value {
119
120
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -122,9 +123,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
122
123
},
123
124
"valid integer as Int64 does not return error when all attributes to sum are unknown" : {
124
125
val : types.Int64 {Value : - 1 },
125
- attributesToSumPaths : []* tftypes. AttributePath {
126
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
127
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
126
+ attributesToSumPaths : []path. Path {
127
+ path . Root ("one" ),
128
+ path . Root ("two" ),
128
129
},
129
130
requestConfigRaw : map [string ]tftypes.Value {
130
131
"one" : tftypes .NewValue (tftypes .Number , tftypes .UnknownValue ),
@@ -133,9 +134,9 @@ func TestAtLeastSumOfValidator(t *testing.T) {
133
134
},
134
135
"error when attribute to sum is not Number" : {
135
136
val : types.Int64 {Value : 9 },
136
- attributesToSumPaths : []* tftypes. AttributePath {
137
- tftypes . NewAttributePath (). WithAttributeName ("one" ),
138
- tftypes . NewAttributePath (). WithAttributeName ("two" ),
137
+ attributesToSumPaths : []path. Path {
138
+ path . Root ("one" ),
139
+ path . Root ("two" ),
139
140
},
140
141
requestConfigRaw : map [string ]tftypes.Value {
141
142
"one" : tftypes .NewValue (tftypes .Bool , true ),
@@ -149,7 +150,7 @@ func TestAtLeastSumOfValidator(t *testing.T) {
149
150
name , test := name , test
150
151
t .Run (name , func (t * testing.T ) {
151
152
request := tfsdk.ValidateAttributeRequest {
152
- AttributePath : tftypes . NewAttributePath (). WithAttributeName ("test" ),
153
+ AttributePath : path . Root ("test" ),
153
154
AttributeConfig : test .val ,
154
155
Config : tfsdk.Config {
155
156
Raw : tftypes .NewValue (tftypes.Object {}, test .requestConfigRaw ),
0 commit comments