Skip to content

Commit

Permalink
PR review
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Bennett <ben.bennett@hashicorp.com>
  • Loading branch information
Ivan De Marino and bendbennett committed Jun 1, 2022
1 parent 2d5bec1 commit 587307a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
13 changes: 5 additions & 8 deletions combovalidator/at_least_one_of.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ func (av atLeastOneOfAttributeValidator) Validate(ctx context.Context, req tfsdk
paths = append(av.attrPaths, req.AttributePath)
}

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

if !v.IsNull() {
count++
return
}
}

if count == 0 {
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
req.AttributePath,
fmt.Sprintf("At least one attribute out of %q must be specified", attributepath.JoinToString(paths...)),
))
}
res.Diagnostics.Append(validatordiag.InvalidCombinationDiagnostic(
req.AttributePath,
fmt.Sprintf("At least one attribute out of %q must be specified", attributepath.JoinToString(paths...)),
))
}
2 changes: 1 addition & 1 deletion combovalidator/at_least_one_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestAtLeastOneOfValidator(t *testing.T) {
tftypes.NewAttributePath().WithAttributeName("foo"),
},
},
"missing-self": {
"self-is-null": {
req: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.String{Null: true},
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),
Expand Down
2 changes: 1 addition & 1 deletion combovalidator/conflicts_with_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestConflictsWithValidator(t *testing.T) {
},
expErrors: 1,
},
"missing-self": {
"self-is-null": {
req: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.String{Null: true},
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),
Expand Down
2 changes: 1 addition & 1 deletion combovalidator/exactly_one_of_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestExactlyOneOfValidator(t *testing.T) {
},
expErrors: 1,
},
"missing-self": {
"self-is-null": {
req: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.String{Null: true},
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),
Expand Down
2 changes: 1 addition & 1 deletion combovalidator/required_with_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestRequiredWithValidator(t *testing.T) {
tftypes.NewAttributePath().WithAttributeName("foo"),
},
},
"missing-self": {
"self-is-null": {
req: tfsdk.ValidateAttributeRequest{
AttributeConfig: types.String{Null: true},
AttributePath: tftypes.NewAttributePath().WithAttributeName("bar"),
Expand Down

0 comments on commit 587307a

Please sign in to comment.