Skip to content

Commit f006676

Browse files
Ivan De Marinobendbennett
andcommitted
PR review
Co-authored-by: Benjamin Bennett <ben.bennett@hashicorp.com>
1 parent 05ee75d commit f006676

5 files changed

Lines changed: 9 additions & 12 deletions

File tree

combovalidator/at_least_one_of.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ func (av atLeastOneOfAttributeValidator) Validate(ctx context.Context, req tfsdk
4444
paths = append(av.attrPaths, req.AttributePath)
4545
}
4646

47-
count := 0
4847
for _, path := range paths {
4948
var v attr.Value
5049
diags := req.Config.GetAttribute(ctx, path, &v)
@@ -54,14 +53,12 @@ func (av atLeastOneOfAttributeValidator) Validate(ctx context.Context, req tfsdk
5453
}
5554

5655
if !v.IsNull() {
57-
count++
56+
return
5857
}
5958
}
6059

61-
if count == 0 {
62-
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
63-
req.AttributePath,
64-
fmt.Sprintf("At least one attribute out of %q must be specified", attributepath.JoinToString(paths...)),
65-
))
66-
}
60+
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
61+
req.AttributePath,
62+
fmt.Sprintf("At least one attribute out of %q must be specified", attributepath.JoinToString(paths...)),
63+
))
6764
}

combovalidator/at_least_one_of_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestAtLeastOneOfValidator(t *testing.T) {
5151
tftypes.NewAttributePath().WithAttributeName("foo"),
5252
},
5353
},
54-
"missing-self": {
54+
"self-is-null": {
5555
req: tfsdk.ValidateAttributeRequest{
5656
AttributeConfig: types.String{Null: true},
5757
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),

combovalidator/conflicts_with_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestConflictsWithValidator(t *testing.T) {
119119
},
120120
expErrors: 1,
121121
},
122-
"missing-self": {
122+
"self-is-null": {
123123
req: tfsdk.ValidateAttributeRequest{
124124
AttributeConfig: types.String{Null: true},
125125
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),

combovalidator/exactly_one_of_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestExactlyOneOfValidator(t *testing.T) {
5252
},
5353
expErrors: 1,
5454
},
55-
"missing-self": {
55+
"self-is-null": {
5656
req: tfsdk.ValidateAttributeRequest{
5757
AttributeConfig: types.String{Null: true},
5858
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),

combovalidator/required_with_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestRequiredWithValidator(t *testing.T) {
5151
tftypes.NewAttributePath().WithAttributeName("foo"),
5252
},
5353
},
54-
"missing-self": {
54+
"self-is-null": {
5555
req: tfsdk.ValidateAttributeRequest{
5656
AttributeConfig: types.String{Null: true},
5757
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),

0 commit comments

Comments
 (0)