Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing schemavalidator package #32

Merged
merged 20 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/32.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
Introduced `schemavalidator` package with 4 new validation functions: `RequiredWith()`, `ConflictsWith()`, `AtLeastOneOf()`, `ExactlyOneOf()`
```
5 changes: 3 additions & 2 deletions float64validator/at_least_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func TestAtLeastValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
float64validator.AtLeast(test.min).Validate(context.TODO(), request, &response)
Expand Down
5 changes: 3 additions & 2 deletions float64validator/at_most_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func TestAtMostValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
float64validator.AtMost(test.max).Validate(context.TODO(), request, &response)
Expand Down
5 changes: 3 additions & 2 deletions float64validator/between_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ func TestBetweenValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
float64validator.Between(test.min, test.max).Validate(context.TODO(), request, &response)
Expand Down
7 changes: 3 additions & 4 deletions float64validator/none_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -73,12 +72,12 @@ func TestNoneOfValidator(t *testing.T) {
t.Fatalf("expected %d error(s), got none", test.expErrors)
}

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

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions float64validator/one_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"testing"

"github.com/hashicorp/terraform-plugin-framework-validators/float64validator"
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
Expand Down Expand Up @@ -73,12 +72,12 @@ func TestOneOfValidator(t *testing.T) {
t.Fatalf("expected %d error(s), got none", test.expErrors)
}

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

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
Expand Down
20 changes: 12 additions & 8 deletions float64validator/type_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,36 @@ func TestValidateFloat(t *testing.T) {
}{
"invalid-type": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Bool{Value: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Bool{Value: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedFloat64: 0.0,
expectedOk: false,
},
"float64-null": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Float64{Null: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Float64{Null: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedFloat64: 0.0,
expectedOk: false,
},
"float64-value": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Float64{Value: 1.2},
AttributePath: path.Root("test"),
AttributeConfig: types.Float64{Value: 1.2},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedFloat64: 1.2,
expectedOk: true,
},
"float64-unknown": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Float64{Unknown: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Float64{Unknown: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedFloat64: 0.0,
expectedOk: false,
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ go 1.17

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

require (
github.com/fatih/color v1.13.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.1 // indirect
github.com/hashicorp/terraform-plugin-go v0.10.0 // indirect
github.com/hashicorp/terraform-plugin-log v0.4.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
Expand Down
13 changes: 4 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,17 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v1.2.0/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39EeqMAyrmvFQ=
github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw=
github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-plugin v1.4.4/go.mod h1:viDMjcLJuDui6pXb8U4HVfb8AamCWhHGUjr2IrTF67s=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220627174514-5a338a7dd906 h1:Y9JWkRpLhbJfdN85Dx+joLWRiwzLlZQkhf1qSbyPJI8=
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220627174514-5a338a7dd906/go.mod h1:ActelD2V6yt2m0MwIX4jESGDYJ573rAvZswGjSGm1rY=
github.com/hashicorp/terraform-plugin-go v0.9.1/go.mod h1:ItjVSlQs70otlzcCwlPcU8FRXLdO973oYFRZwAOxy8M=
github.com/hashicorp/terraform-plugin-go v0.10.0 h1:FIQDt/AZDSOXnN+znBnLLZA9aFk4/GwL40rwMLnvuTk=
github.com/hashicorp/terraform-plugin-go v0.10.0/go.mod h1:aphXBG8qtQH0yF1waMRlaw/3G+ZFlR/6Artnvt1QEDE=
github.com/hashicorp/terraform-plugin-log v0.4.0/go.mod h1:9KclxdunFownr4pIm1jdmwKRmE4d6HVG2c9XDq47rpg=
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220711170800-89baaa204707 h1:4wAdubsgZ/eAbCjW2At8w6UDeVCel76jWDHsWvbc8Pk=
github.com/hashicorp/terraform-plugin-framework v0.9.1-0.20220711170800-89baaa204707/go.mod h1:+H4ieVu7X4bfYlLB/zytek48e4CjcG+gjKdVOjVY1PU=
github.com/hashicorp/terraform-plugin-go v0.11.0 h1:YXsvSCx7GbQO5jIUQd77FesqmIBxgSvYAtAX1NqErTk=
github.com/hashicorp/terraform-plugin-go v0.11.0/go.mod h1:aphXBG8qtQH0yF1waMRlaw/3G+ZFlR/6Artnvt1QEDE=
github.com/hashicorp/terraform-plugin-log v0.4.1 h1:xpbmVhvuU3mgHzLetOmx9pkOL2rmgpu302XxddON6eo=
github.com/hashicorp/terraform-plugin-log v0.4.1/go.mod h1:p4R1jWBXRTvL4odmEkFfDdhUjHf9zcs/BCoNHAc7IK4=
github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896/go.mod h1:bzBPnUIkI0RxauU8Dqo+2KrZZ28Cf48s8V6IHt3p4co=
github.com/hashicorp/terraform-registry-address v0.0.0-20220623143253-7d51757b572c/go.mod h1:Wn3Na71knbXc1G8Lh+yu/dQWWJeFQEpDeJMtWMtlmNI=
github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg=
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
Expand Down Expand Up @@ -191,7 +187,6 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
google.golang.org/grpc v1.46.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc v1.47.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACuMGWk=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0/go.mod h1:DNq5QpG7LJqD2AamLZ7zvKE0DEpVl2BSEVjFycAAjRY=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
Expand Down
32 changes: 6 additions & 26 deletions helpers/validatordiag/diag.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func InvalidAttributeValueMatchDiagnostic(path path.Path, description string, va
)
}

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

// ErrorsCount returns the amount of diag.Diagnostic in diag.Diagnostics that are diag.SeverityError.
func ErrorsCount(diags diag.Diagnostics) int {
count := 0

for _, d := range diags {
if diag.SeverityError == d.Severity() {
count++
}
}

return count
}

// WarningsCount returns the amount of diag.Diagnostic in diag.Diagnostics that are diag.SeverityWarning.
func WarningsCount(diags diag.Diagnostics) int {
count := 0

for _, d := range diags {
if diag.SeverityWarning == d.Severity() {
count++
}
}

return count
func BugInProviderDiagnostic(summary string) diag.Diagnostic {
return diag.NewErrorDiagnostic(summary,
"This is a bug in the provider, which should be reported in the provider's own issue tracker",
)
}

// capitalize will uppercase the first letter in a UTF-8 string.
Expand Down
5 changes: 3 additions & 2 deletions int64validator/at_least_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func TestAtLeastValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
int64validator.AtLeast(test.min).Validate(context.TODO(), request, &response)
Expand Down
5 changes: 3 additions & 2 deletions int64validator/at_most_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func TestAtMostValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
int64validator.AtMost(test.max).Validate(context.TODO(), request, &response)
Expand Down
5 changes: 3 additions & 2 deletions int64validator/between_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ func TestBetweenValidator(t *testing.T) {
name, test := name, test
t.Run(name, func(t *testing.T) {
request := tfsdk.ValidateAttributeRequest{
AttributePath: path.Root("test"),
AttributeConfig: test.val,
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
AttributeConfig: test.val,
}
response := tfsdk.ValidateAttributeResponse{}
int64validator.Between(test.min, test.max).Validate(context.TODO(), request, &response)
Expand Down
7 changes: 3 additions & 4 deletions int64validator/none_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

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

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

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
Expand Down
7 changes: 3 additions & 4 deletions int64validator/one_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"testing"

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

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

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
Expand Down
20 changes: 12 additions & 8 deletions int64validator/type_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,36 @@ func TestValidateInt(t *testing.T) {
}{
"invalid-type": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Bool{Value: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Bool{Value: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedInt64: 0.0,
expectedOk: false,
},
"int64-null": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Int64{Null: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Int64{Null: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedInt64: 0.0,
expectedOk: false,
},
"int64-value": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Int64{Value: 123},
AttributePath: path.Root("test"),
AttributeConfig: types.Int64{Value: 123},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedInt64: 123,
expectedOk: true,
},
"int64-unknown": {
request: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.Int64{Unknown: true},
AttributePath: path.Root("test"),
AttributeConfig: types.Int64{Unknown: true},
AttributePath: path.Root("test"),
AttributePathExpression: path.MatchRoot("test"),
},
expectedInt64: 0.0,
expectedOk: false,
Expand Down
7 changes: 3 additions & 4 deletions internal/primitivevalidator/none_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"math/big"
"testing"

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

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

if test.expErrors == 0 && res.Diagnostics.HasError() {
t.Fatalf("expected no error(s), got %d: %v", validatordiag.ErrorsCount(res.Diagnostics), res.Diagnostics)
t.Fatalf("expected no error(s), got %d: %v", res.Diagnostics.ErrorsCount(), res.Diagnostics)
}
})
}
Expand Down
Loading