Skip to content

Commit df13514

Browse files
author
Ivan De Marino
committed
PR review
1 parent 699e751 commit df13514

21 files changed

Lines changed: 40 additions & 26 deletions

.changelog/42.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ numbervalidator: New package that starts with 2 validation functions, `OneOf()`
1111
```
1212

1313
```release-note:enhancement
14-
stringvalidator: 2 new validation functions, `OneOf()` and `NoneOf()`, similar to the ones in `genericvalidator` but option to control case-sensitivity
14+
stringvalidator: 2 new validation functions, `OneOf()` and `NoneOf()`, that offer case-sensitivity control
1515
```

float64validator/at_least.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator atLeastValidator) Validate(ctx context.Context, request tfsdk.Va
3434
}
3535

3636
if f < validator.min {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%f", f),

float64validator/at_most.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator atMostValidator) Validate(ctx context.Context, request tfsdk.Val
3434
}
3535

3636
if f > validator.max {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%f", f),

float64validator/between.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator betweenValidator) Validate(ctx context.Context, request tfsdk.Va
3434
}
3535

3636
if f < validator.min || f > validator.max {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%f", f),

float64validator/type_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func validateFloat(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) (float64, bool) {
1313
t := request.AttributeConfig.Type(ctx)
1414
if t != types.Float64Type {
15-
response.Diagnostics.Append(validatordiag.InvalidTypeDiagnostic(
15+
response.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
1616
request.AttributePath,
1717
"Expected value of type float64",
1818
t.String(),

helpers/validatordiag/diag.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,44 @@ import (
88
"github.com/hashicorp/terraform-plugin-go/tftypes"
99
)
1010

11-
// InvalidValueDiagnostic returns an error Diagnostic to be used when an attribute has an invalid value.
12-
func InvalidValueDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
11+
// InvalidAttributeValueDiagnostic returns an error Diagnostic to be used when an attribute has an invalid value.
12+
func InvalidAttributeValueDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
1313
return diag.NewAttributeErrorDiagnostic(
1414
path,
1515
"Invalid Attribute Value",
1616
capitalize(description)+", got: "+value,
1717
)
1818
}
1919

20-
// InvalidValueLengthDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid length.
21-
func InvalidValueLengthDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
20+
// InvalidAttributeValueLengthDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid length.
21+
func InvalidAttributeValueLengthDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
2222
return diag.NewAttributeErrorDiagnostic(
2323
path,
2424
"Invalid Attribute Value Length",
2525
capitalize(description)+", got: "+value,
2626
)
2727
}
2828

29-
// InvalidValueMatchDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid match.
30-
func InvalidValueMatchDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
29+
// InvalidAttributeValueMatchDiagnostic returns an error Diagnostic to be used when an attribute's value has an invalid match.
30+
func InvalidAttributeValueMatchDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
3131
return diag.NewAttributeErrorDiagnostic(
3232
path,
3333
"Invalid Attribute Value Match",
3434
capitalize(description)+", got: "+value,
3535
)
3636
}
3737

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 {
38+
// InvalidAttributeSchemaDiagnostic returns an error Diagnostic to be used when a schemavalidator of attributes is invalid.
39+
func InvalidAttributeSchemaDiagnostic(path *tftypes.AttributePath, description string) diag.Diagnostic {
4040
return diag.NewAttributeErrorDiagnostic(
4141
path,
4242
"Invalid Attribute Combination",
4343
capitalize(description),
4444
)
4545
}
4646

47-
// InvalidTypeDiagnostic returns an error Diagnostic to be used when an attribute has an invalid type.
48-
func InvalidTypeDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
47+
// InvalidAttributeTypeDiagnostic returns an error Diagnostic to be used when an attribute has an invalid type.
48+
func InvalidAttributeTypeDiagnostic(path *tftypes.AttributePath, description string, value string) diag.Diagnostic {
4949
return diag.NewAttributeErrorDiagnostic(
5050
path,
5151
"Invalid Attribute Type",

int64validator/at_least.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator atLeastValidator) Validate(ctx context.Context, request tfsdk.Va
3434
}
3535

3636
if i < validator.min {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%d", i),

int64validator/at_most.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator atMostValidator) Validate(ctx context.Context, request tfsdk.Val
3434
}
3535

3636
if i > validator.max {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%d", i),

int64validator/between.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (validator betweenValidator) Validate(ctx context.Context, request tfsdk.Va
3434
}
3535

3636
if i < validator.min || i > validator.max {
37-
response.Diagnostics.Append(validatordiag.InvalidValueDiagnostic(
37+
response.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
3838
request.AttributePath,
3939
validator.Description(ctx),
4040
fmt.Sprintf("%d", i),

int64validator/type_validation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func validateInt(ctx context.Context, request tfsdk.ValidateAttributeRequest, response *tfsdk.ValidateAttributeResponse) (int64, bool) {
1313
t := request.AttributeConfig.Type(ctx)
1414
if t != types.Int64Type {
15-
response.Diagnostics.Append(validatordiag.InvalidTypeDiagnostic(
15+
response.Diagnostics.Append(validatordiag.InvalidAttributeTypeDiagnostic(
1616
request.AttributePath,
1717
"Expected value of type int64",
1818
t.String(),

0 commit comments

Comments
 (0)