Skip to content

Commit 2f64d4c

Browse files
authored
fix: show correct min and max values in validation errors (#122)
1 parent 946db5a commit 2f64d4c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: provider/parameter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,10 +438,10 @@ func (v *Validation) Valid(typ, value string) error {
438438
return fmt.Errorf("value %q is not a number", value)
439439
}
440440
if v.Min != nil && num < *v.Min {
441-
return fmt.Errorf("value %d is less than the minimum %d", num, v.Min)
441+
return fmt.Errorf("value %d is less than the minimum %d", num, *v.Min)
442442
}
443443
if v.Max != nil && num > *v.Max {
444-
return fmt.Errorf("value %d is more than the maximum %d", num, v.Max)
444+
return fmt.Errorf("value %d is more than the maximum %d", num, *v.Max)
445445
}
446446
if v.Monotonic != "" && v.Monotonic != ValidationMonotonicIncreasing && v.Monotonic != ValidationMonotonicDecreasing {
447447
return fmt.Errorf("number monotonicity can be either %q or %q", ValidationMonotonicIncreasing, ValidationMonotonicDecreasing)

Diff for: provider/parameter_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -499,13 +499,13 @@ func TestValueValidatesType(t *testing.T) {
499499
Type: "number",
500500
Value: "0",
501501
Min: ptrNumber(1),
502-
Error: regexp.MustCompile("is less than the minimum"),
502+
Error: regexp.MustCompile("is less than the minimum 1"),
503503
}, {
504504
Name: "NumberAboveMax",
505505
Type: "number",
506506
Value: "2",
507507
Max: ptrNumber(1),
508-
Error: regexp.MustCompile("is more than the maximum"),
508+
Error: regexp.MustCompile("is more than the maximum 1"),
509509
}, {
510510
Name: "InvalidBool",
511511
Type: "bool",

0 commit comments

Comments
 (0)