Skip to content

Commit d73c21a

Browse files
author
Ivan De Marino
committed
Renamed combovalidator to schemavalidator package name
1 parent f006676 commit d73c21a

12 files changed

Lines changed: 29 additions & 27 deletions

File tree

.changelog/32.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Renaming package `validatordiag` to be at `helpers/validatordiag`.
33
```
44

55
```release-note:feature
6-
Introduced `combovalidator` package with 4 new validation functions: `RequiredWith()`, `ConflictsWith()`, `AtLeastOneOf()`, `ExactlyOneOf()`.
6+
Introduced `schemavalidator` package with 4 new validation functions: `RequiredWith()`, `ConflictsWith()`, `AtLeastOneOf()`, `ExactlyOneOf()`.
77
```
88

99
```release-note:feature

combovalidator/doc.go

Lines changed: 0 additions & 3 deletions
This file was deleted.

helpers/validatordiag/diag.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func InvalidValueMatchDiagnostic(path *tftypes.AttributePath, description string
3535
)
3636
}
3737

38-
// InvalidCombinationDiagnostic returns an error Diagnostic to be used when a combovalidator of attribugtes is invalid.
39-
func InvalidCombinationDiagnostic(path *tftypes.AttributePath, description string) diag.Diagnostic {
38+
// InvalidSchemaDiagnostic returns an error Diagnostic to be used when a schemavalidator of attributes is invalid.
39+
func InvalidSchemaDiagnostic(path *tftypes.AttributePath, description string) diag.Diagnostic {
4040
return diag.NewAttributeErrorDiagnostic(
4141
path,
4242
"Invalid Attribute Combination",
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package combovalidator
1+
package schemavalidator
22

33
import (
44
"context"
@@ -57,7 +57,7 @@ func (av atLeastOneOfAttributeValidator) Validate(ctx context.Context, req tfsdk
5757
}
5858
}
5959

60-
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
60+
res.Diagnostics.Append(validatordiag.InvalidSchemaDiagnostic(
6161
req.AttributePath,
6262
fmt.Sprintf("At least one attribute out of %q must be specified", attributepath.JoinToString(paths...)),
6363
))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package combovalidator_test
1+
package schemavalidator_test
22

33
import (
44
"context"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-framework-validators/combovalidator"
87
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
99
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -233,7 +233,7 @@ func TestAtLeastOneOfValidator(t *testing.T) {
233233
t.Run(name, func(t *testing.T) {
234234
res := tfsdk.ValidateAttributeResponse{}
235235

236-
combovalidator.AtLeastOneOf(test.in...).Validate(context.TODO(), test.req, &res)
236+
schemavalidator.AtLeastOneOf(test.in...).Validate(context.TODO(), test.req, &res)
237237

238238
if test.expErrors > 0 && !res.Diagnostics.HasError() {
239239
t.Fatal("expected error(s), got none")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package combovalidator
1+
package schemavalidator
22

33
import (
44
"context"
@@ -58,7 +58,7 @@ func (av conflictsWithAttributeValidator) Validate(ctx context.Context, req tfsd
5858
}
5959

6060
if !v.IsNull() && !o.IsNull() {
61-
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
61+
res.Diagnostics.Append(validatordiag.InvalidSchemaDiagnostic(
6262
req.AttributePath,
6363
fmt.Sprintf("Attribute %q cannot be specified when %q is specified", attributepath.ToString(path), attributepath.ToString(req.AttributePath)),
6464
))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package combovalidator_test
1+
package schemavalidator_test
22

33
import (
44
"context"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-framework-validators/combovalidator"
87
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
99
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -230,7 +230,7 @@ func TestConflictsWithValidator(t *testing.T) {
230230
t.Run(name, func(t *testing.T) {
231231
res := tfsdk.ValidateAttributeResponse{}
232232

233-
combovalidator.ConflictsWith(test.in...).Validate(context.TODO(), test.req, &res)
233+
schemavalidator.ConflictsWith(test.in...).Validate(context.TODO(), test.req, &res)
234234

235235
if test.expErrors > 0 && !res.Diagnostics.HasError() {
236236
t.Fatal("expected error(s), got none")

schemavalidator/doc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Package schemavalidator provides validators that allow to express
2+
// relationships between multiple attributes within the schema of a resource,
3+
// data source or provider.
4+
// For example, checking that an attribute is present when another is present, or vice-versa.
5+
package schemavalidator
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package combovalidator
1+
package schemavalidator
22

33
import (
44
"context"
@@ -60,14 +60,14 @@ func (av exactlyOneOfAttributeValidator) Validate(ctx context.Context, req tfsdk
6060
}
6161

6262
if count == 0 {
63-
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
63+
res.Diagnostics.Append(validatordiag.InvalidSchemaDiagnostic(
6464
req.AttributePath,
6565
fmt.Sprintf("No attribute specified when one (and only one) of %q is required", attributepath.JoinToString(paths...)),
6666
))
6767
}
6868

6969
if count > 1 {
70-
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
70+
res.Diagnostics.Append(validatordiag.InvalidSchemaDiagnostic(
7171
req.AttributePath,
7272
fmt.Sprintf("%d attributes specified when one (and only one) of %q is required", count, attributepath.JoinToString(paths...)),
7373
))
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package combovalidator_test
1+
package schemavalidator_test
22

33
import (
44
"context"
55
"testing"
66

7-
"github.com/hashicorp/terraform-plugin-framework-validators/combovalidator"
87
"github.com/hashicorp/terraform-plugin-framework-validators/helpers/validatordiag"
8+
"github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator"
99
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1010
"github.com/hashicorp/terraform-plugin-framework/types"
1111
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -236,7 +236,7 @@ func TestExactlyOneOfValidator(t *testing.T) {
236236
t.Run(name, func(t *testing.T) {
237237
res := tfsdk.ValidateAttributeResponse{}
238238

239-
combovalidator.ExactlyOneOf(test.in...).Validate(context.TODO(), test.req, &res)
239+
schemavalidator.ExactlyOneOf(test.in...).Validate(context.TODO(), test.req, &res)
240240

241241
if test.expErrors > 0 && !res.Diagnostics.HasError() {
242242
t.Fatal("expected error(s), got none")

0 commit comments

Comments
 (0)