Skip to content

Commit

Permalink
improve ParseRangeOfIntValidator. update port_range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
tmunzer committed Jul 30, 2024
1 parent fc3a115 commit 0acb0ba
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 14 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/resource_org_service/org_service_resource_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/resource_org_wlan/org_wlan_resource_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/resource_org_wxtag/org_wxtag_resource_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/resource_site_wlan/site_wlan_resource_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/resource_site_wxtag/site_wxtag_resource_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions internal/validators/parse_range_int.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import (
var _ validator.String = ParseRangeOfIntValidator{}

type ParseRangeOfIntValidator struct {
min int
max int
min int
max int
equal_allowed bool
}

func (o ParseRangeOfIntValidator) Description(_ context.Context) string {
Expand Down Expand Up @@ -55,7 +56,7 @@ func (o ParseRangeOfIntValidator) ValidateString(_ context.Context, req validato

value_one, _ := strconv.Atoi(values[0])
value_two, _ := strconv.Atoi(values[1])
if value_one >= value_two {
if (!o.equal_allowed && value_one >= value_two) || (o.equal_allowed && value_one > value_two) {
resp.Diagnostics.Append(validatordiag.InvalidAttributeValueDiagnostic(
req.Path,
fmt.Sprintf("must be a range of Integers between %s and %s, meaning the first value must be lower than the second value", strconv.Itoa(o.min), strconv.Itoa(o.max)),
Expand All @@ -65,9 +66,10 @@ func (o ParseRangeOfIntValidator) ValidateString(_ context.Context, req validato
}
}

func ParseRangeOfInt(min int, max int) validator.String {
func ParseRangeOfInt(min int, max int, equalAlloweds bool) validator.String {
return ParseRangeOfIntValidator{
min: min,
max: max,
min: min,
max: max,
equal_allowed: equalAlloweds,
}
}

0 comments on commit 0acb0ba

Please sign in to comment.