Skip to content

Commit 81783a7

Browse files
Ivan De Marinobflad
Ivan De Marino
andauthored
Introducing schemavalidator package (#32)
* Marking unused arguments as such * temporary: attributepath helpers * Introducing `schemavalidator` package * CHANGELOG entry * Removing any reference to `tftypes.AttributePath` in favour of `path.*` * Bump up to latest version of `terraform-plugin-framework` * Fix changelog entries * Update helpers with a `pathutils` sub-package to help with the new `path.Expressions` manipulation * Update all `schemavalidator`s to use `path.Expressions` * Updating dependencies * Update .changelog/42.txt Co-authored-by: Brian Flad <[email protected]> * Apply suggestions from code review Co-authored-by: Brian Flad <[email protected]> * Update schemavalidator/at_least_one_of.go Co-authored-by: Brian Flad <[email protected]> * PR review feedback * Making the `schemavalidator` permissive when the involved attributes' values are `Unknown` * Further PR review tweaks * Renamed 'RequiredWith' to 'AlsoRequires', and also updated the godoc * Making use of the new `.Append()` method added to `path.Paths` and `path.Expressions` * deps: Update github.com/hashicorp/terraform-plugin-framework@main * schemavalidator: Updates to use (Expression).MergeExpressions() Co-authored-by: Brian Flad <[email protected]>
1 parent 9b3598d commit 81783a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1755
-204
lines changed

.changelog/32.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:feature
2+
Introduced `schemavalidator` package with 4 new validation functions: `RequiredWith()`, `ConflictsWith()`, `AtLeastOneOf()`, `ExactlyOneOf()`
3+
```

float64validator/at_least_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ func TestAtLeastValidator(t *testing.T) {
5555
name, test := name, test
5656
t.Run(name, func(t *testing.T) {
5757
request := tfsdk.ValidateAttributeRequest{
58-
AttributePath: path.Root("test"),
59-
AttributeConfig: test.val,
58+
AttributePath: path.Root("test"),
59+
AttributePathExpression: path.MatchRoot("test"),
60+
AttributeConfig: test.val,
6061
}
6162
response := tfsdk.ValidateAttributeResponse{}
6263
float64validator.AtLeast(test.min).Validate(context.TODO(), request, &response)

float64validator/at_most_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,9 @@ func TestAtMostValidator(t *testing.T) {
5555
name, test := name, test
5656
t.Run(name, func(t *testing.T) {
5757
request := tfsdk.ValidateAttributeRequest{
58-
AttributePath: path.Root("test"),
59-
AttributeConfig: test.val,
58+
AttributePath: path.Root("test"),
59+
AttributePathExpression: path.MatchRoot("test"),
60+
AttributeConfig: test.val,
6061
}
6162
response := tfsdk.ValidateAttributeResponse{}
6263
float64validator.AtMost(test.max).Validate(context.TODO(), request, &response)

float64validator/between_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ func TestBetweenValidator(t *testing.T) {
7373
name, test := name, test
7474
t.Run(name, func(t *testing.T) {
7575
request := tfsdk.ValidateAttributeRequest{
76-
AttributePath: path.Root("test"),
77-
AttributeConfig: test.val,
76+
AttributePath: path.Root("test"),
77+
AttributePathExpression: path.MatchRoot("test"),
78+
AttributeConfig: test.val,
7879
}
7980
response := tfsdk.ValidateAttributeResponse{}
8081
float64validator.Between(test.min, test.max).Validate(context.TODO(), request, &response)

float64validator/none_of_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
8-
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
98
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1110
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -73,12 +72,12 @@ func TestNoneOfValidator(t *testing.T) {
7372
t.Fatalf("expected %d error(s), got none", test.expErrors)
7473
}
7574

76-
if test.expErrors > 0 && test.expErrors != validatordiag.ErrorsCount(res.Diagnostics) {
77-
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
75+
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
76+
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
7877
}
7978

8079
if test.expErrors == 0 && res.Diagnostics.HasError() {
81-
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
80+
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
8281
}
8382
})
8483
}

float64validator/one_of_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
8-
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
98
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1110
"github.com/hashicorp/terraform-plugin-framework/types"
@@ -73,12 +72,12 @@ func TestOneOfValidator(t *testing.T) {
7372
t.Fatalf("expected %d error(s), got none", test.expErrors)
7473
}
7574

76-
if test.expErrors > 0 && test.expErrors != validatordiag.ErrorsCount(res.Diagnostics) {
77-
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
75+
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
76+
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
7877
}
7978

8079
if test.expErrors == 0 && res.Diagnostics.HasError() {
81-
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
80+
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
8281
}
8382
})
8483
}

float64validator/type_validation_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,36 @@ func TestValidateFloat(t *testing.T) {
2020
}{
2121
"invalid-type": {
2222
request: tfsdk.ValidateAttributeRequest{
23-
AttributeConfig: types.Bool{Value: true},
24-
AttributePath: path.Root("test"),
23+
AttributeConfig: types.Bool{Value: true},
24+
AttributePath: path.Root("test"),
25+
AttributePathExpression: path.MatchRoot("test"),
2526
},
2627
expectedFloat64: 0.0,
2728
expectedOk: false,
2829
},
2930
"float64-null": {
3031
request: tfsdk.ValidateAttributeRequest{
31-
AttributeConfig: types.Float64{Null: true},
32-
AttributePath: path.Root("test"),
32+
AttributeConfig: types.Float64{Null: true},
33+
AttributePath: path.Root("test"),
34+
AttributePathExpression: path.MatchRoot("test"),
3335
},
3436
expectedFloat64: 0.0,
3537
expectedOk: false,
3638
},
3739
"float64-value": {
3840
request: tfsdk.ValidateAttributeRequest{
39-
AttributeConfig: types.Float64{Value: 1.2},
40-
AttributePath: path.Root("test"),
41+
AttributeConfig: types.Float64{Value: 1.2},
42+
AttributePath: path.Root("test"),
43+
AttributePathExpression: path.MatchRoot("test"),
4144
},
4245
expectedFloat64: 1.2,
4346
expectedOk: true,
4447
},
4548
"float64-unknown": {
4649
request: tfsdk.ValidateAttributeRequest{
47-
AttributeConfig: types.Float64{Unknown: true},
48-
AttributePath: path.Root("test"),
50+
AttributeConfig: types.Float64{Unknown: true},
51+
AttributePath: path.Root("test"),
52+
AttributePathExpression: path.MatchRoot("test"),
4953
},
5054
expectedFloat64: 0.0,
5155
expectedOk: false,

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ go 1.17
44

55
require (
66
github.com/google/go-cmp v0.5.8
7-
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220627174514-5a338a7dd906
7+
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220711170800-89baaa204707
8+
github.com/hashicorp/terraform-plugin-go v0.11.0
89
)
910

1011
require (
1112
github.com/fatih/color v1.13.0 // indirect
1213
github.com/golang/protobuf v1.5.2 // indirect
1314
github.com/hashicorp/go-hclog v1.2.1 // indirect
14-
github.com/hashicorp/terraform-plugin-go v0.10.0 // indirect
1515
github.com/hashicorp/terraform-plugin-log v0.4.1 // indirect
1616
github.com/mattn/go-colorable v0.1.12 // indirect
1717
github.com/mattn/go-isatty v0.0.14 // indirect

go.sum

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,17 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
5757
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
5858
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
5959
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
60-
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
6160
github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw=
6261
github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
6362
github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
6463
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
6564
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
66-
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220627174514-5a338a7dd906 h1:Y9JWkRpLhbJfdN85Dx+joLWRiwzLlZQkhf1qSbyPJI8=
67-
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220627174514-5a338a7dd906/go.mod h1:ActelD2V6yt2m0MwIX4jESGDYJ573rAvZswGjSGm1rY=
68-
github.com/hashicorp/terraform-plugin-go v0.9.1/go.mod h1:ItjVSlQs70otlzcCwlPcU8FRXLdO973oYFRZwAOxy8M=
69-
github.com/hashicorp/terraform-plugin-go v0.10.0 h1:FIQDt/AZDSOXnN+znBnLLZA9aFk4/GwL40rwMLnvuTk=
70-
github.com/hashicorp/terraform-plugin-go v0.10.0/go.mod h1:aphXBG8qtQH0yF1waMRlaw/3G+ZFlR/6Artnvt1QEDE=
71-
github.com/hashicorp/terraform-plugin-log v0.4.0/go.mod h1:9KclxdunFownr4pIm1jdmwKRmE4d6HVG2c9XDq47rpg=
65+
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220711170800-89baaa204707 h1:4wAdubsgZ/eAbCjW2At8w6UDeVCel76jWDHsWvbc8Pk=
66+
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220711170800-89baaa204707/go.mod h1:+H4ieVu7X4bfYlLB/zytek48e4CjcG+gjKdVOjVY1PU=
67+
github.com/hashicorp/terraform-plugin-go v0.11.0 h1:YXsvSCx7GbQO5jIUQd77FesqmIBxgSvYAtAX1NqErTk=
68+
github.com/hashicorp/terraform-plugin-go v0.11.0/go.mod h1:aphXBG8qtQH0yF1waMRlaw/3G+ZFlR/6Artnvt1QEDE=
7269
github.com/hashicorp/terraform-plugin-log v0.4.1 h1:xpbmVhvuU3mgHzLetOmx9pkOL2rmgpu302XxddON6eo=
7370
github.com/hashicorp/terraform-plugin-log v0.4.1/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
74-
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
7571
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
7672
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
7773
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
@@ -191,7 +187,6 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
191187
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
192188
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
193189
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
194-
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
195190
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
196191
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY=
197192
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=

helpers/validatordiag/diag.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func InvalidAttributeValueMatchDiagnostic(path path.Path, description string, va
3535
)
3636
}
3737

38-
// InvalidAttributeSchemaDiagnostic returns an error Diagnostic to be used when a schemavalidator of attributes is invalid.
39-
func InvalidAttributeSchemaDiagnostic(path path.Path, description string) diag.Diagnostic {
38+
// InvalidAttributeCombinationDiagnostic returns an error Diagnostic to be used when a schemavalidator of attributes is invalid.
39+
func InvalidAttributeCombinationDiagnostic(path path.Path, description string) diag.Diagnostic {
4040
return diag.NewAttributeErrorDiagnostic(
4141
path,
4242
"Invalid Attribute Combination",
@@ -53,30 +53,10 @@ func InvalidAttributeTypeDiagnostic(path path.Path, description string, value st
5353
)
5454
}
5555

56-
// ErrorsCount returns the amount of diag.Diagnostic in diag.Diagnostics that are diag.SeverityError.
57-
func ErrorsCount(diags diag.Diagnostics) int {
58-
count := 0
59-
60-
for _, d := range diags {
61-
if diag.SeverityError == d.Severity() {
62-
count++
63-
}
64-
}
65-
66-
return count
67-
}
68-
69-
// WarningsCount returns the amount of diag.Diagnostic in diag.Diagnostics that are diag.SeverityWarning.
70-
func WarningsCount(diags diag.Diagnostics) int {
71-
count := 0
72-
73-
for _, d := range diags {
74-
if diag.SeverityWarning == d.Severity() {
75-
count++
76-
}
77-
}
78-
79-
return count
56+
func BugInProviderDiagnostic(summary string) diag.Diagnostic {
57+
return diag.NewErrorDiagnostic(summary,
58+
"This is a bug in the provider, which should be reported in the provider's own issue tracker",
59+
)
8060
}
8161

8262
// capitalize will uppercase the first letter in a UTF-8 string.

int64validator/at_least_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ func TestAtLeastValidator(t *testing.T) {
5151
name, test := name, test
5252
t.Run(name, func(t *testing.T) {
5353
request := tfsdk.ValidateAttributeRequest{
54-
AttributePath: path.Root("test"),
55-
AttributeConfig: test.val,
54+
AttributePath: path.Root("test"),
55+
AttributePathExpression: path.MatchRoot("test"),
56+
AttributeConfig: test.val,
5657
}
5758
response := tfsdk.ValidateAttributeResponse{}
5859
int64validator.AtLeast(test.min).Validate(context.TODO(), request, &response)

int64validator/at_most_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ func TestAtMostValidator(t *testing.T) {
5151
name, test := name, test
5252
t.Run(name, func(t *testing.T) {
5353
request := tfsdk.ValidateAttributeRequest{
54-
AttributePath: path.Root("test"),
55-
AttributeConfig: test.val,
54+
AttributePath: path.Root("test"),
55+
AttributePathExpression: path.MatchRoot("test"),
56+
AttributeConfig: test.val,
5657
}
5758
response := tfsdk.ValidateAttributeResponse{}
5859
int64validator.AtMost(test.max).Validate(context.TODO(), request, &response)

int64validator/between_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ func TestBetweenValidator(t *testing.T) {
6868
name, test := name, test
6969
t.Run(name, func(t *testing.T) {
7070
request := tfsdk.ValidateAttributeRequest{
71-
AttributePath: path.Root("test"),
72-
AttributeConfig: test.val,
71+
AttributePath: path.Root("test"),
72+
AttributePathExpression: path.MatchRoot("test"),
73+
AttributeConfig: test.val,
7374
}
7475
response := tfsdk.ValidateAttributeResponse{}
7576
int64validator.Between(test.min, test.max).Validate(context.TODO(), request, &response)

int64validator/none_of_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
87
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
98
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
@@ -73,12 +72,12 @@ func TestNoneOfValidator(t *testing.T) {
7372
t.Fatalf("expected %d error(s), got none", test.expErrors)
7473
}
7574

76-
if test.expErrors > 0 && test.expErrors != validatordiag.ErrorsCount(res.Diagnostics) {
77-
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
75+
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
76+
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
7877
}
7978

8079
if test.expErrors == 0 && res.Diagnostics.HasError() {
81-
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
80+
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
8281
}
8382
})
8483
}

int64validator/one_of_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
87
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
98
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
@@ -73,12 +72,12 @@ func TestOneOfValidator(t *testing.T) {
7372
t.Fatalf("expected %d error(s), got none", test.expErrors)
7473
}
7574

76-
if test.expErrors > 0 && test.expErrors != validatordiag.ErrorsCount(res.Diagnostics) {
77-
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
75+
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
76+
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
7877
}
7978

8079
if test.expErrors == 0 && res.Diagnostics.HasError() {
81-
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
80+
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
8281
}
8382
})
8483
}

int64validator/type_validation_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,36 @@ func TestValidateInt(t *testing.T) {
2020
}{
2121
"invalid-type": {
2222
request: tfsdk.ValidateAttributeRequest{
23-
AttributeConfig: types.Bool{Value: true},
24-
AttributePath: path.Root("test"),
23+
AttributeConfig: types.Bool{Value: true},
24+
AttributePath: path.Root("test"),
25+
AttributePathExpression: path.MatchRoot("test"),
2526
},
2627
expectedInt64: 0.0,
2728
expectedOk: false,
2829
},
2930
"int64-null": {
3031
request: tfsdk.ValidateAttributeRequest{
31-
AttributeConfig: types.Int64{Null: true},
32-
AttributePath: path.Root("test"),
32+
AttributeConfig: types.Int64{Null: true},
33+
AttributePath: path.Root("test"),
34+
AttributePathExpression: path.MatchRoot("test"),
3335
},
3436
expectedInt64: 0.0,
3537
expectedOk: false,
3638
},
3739
"int64-value": {
3840
request: tfsdk.ValidateAttributeRequest{
39-
AttributeConfig: types.Int64{Value: 123},
40-
AttributePath: path.Root("test"),
41+
AttributeConfig: types.Int64{Value: 123},
42+
AttributePath: path.Root("test"),
43+
AttributePathExpression: path.MatchRoot("test"),
4144
},
4245
expectedInt64: 123,
4346
expectedOk: true,
4447
},
4548
"int64-unknown": {
4649
request: tfsdk.ValidateAttributeRequest{
47-
AttributeConfig: types.Int64{Unknown: true},
48-
AttributePath: path.Root("test"),
50+
AttributeConfig: types.Int64{Unknown: true},
51+
AttributePath: path.Root("test"),
52+
AttributePathExpression: path.MatchRoot("test"),
4953
},
5054
expectedInt64: 0.0,
5155
expectedOk: false,

internal/primitivevalidator/none_of_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"math/big"
77
"testing"
88

9-
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
109
"github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator"
1110
"github.com/hashicorp/terraform-plugin-framework/attr"
1211
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
@@ -181,12 +180,12 @@ func TestNoneOfValidator(t *testing.T) {
181180
t.Fatalf("expected %d error(s), got none", test.expErrors)
182181
}
183182

184-
if test.expErrors > 0 && test.expErrors != validatordiag.ErrorsCount(res.Diagnostics) {
185-
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
183+
if test.expErrors > 0 && test.expErrors != res.Diagnostics.ErrorsCount() {
184+
t.Fatalf("expected %d error(s), got %d: %v", test.expErrors, res.Diagnostics.ErrorsCount(), res.Diagnostics)
186185
}
187186

188187
if test.expErrors == 0 && res.Diagnostics.HasError() {
189-
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
188+
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
190189
}
191190
})
192191
}

0 commit comments

Comments
 (0)