Skip to content

Commit

Permalink
Fix int value expected
Browse files Browse the repository at this point in the history
  • Loading branch information
merschformann committed Dec 19, 2024
1 parent 0ea9bbd commit 002f36a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions golden/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -429,14 +429,19 @@ func valuesAreEqual(config Config, key string, output, expected any) error {
}

if outputInt, IsInt := output.(int); IsInt {
expectedFloat, expectedIsFloat := expected.(float64) // JSON unmarshals numbers as float64
expectedInt, expectedIsInt := expected.(int)
if !expectedIsInt {
if !expectedIsInt && !expectedIsFloat {
return fmt.Errorf(
"key \"%s\": output value %v is int, expected value %v is not",
"key \"%s\": output value %v is int, expected value %v is not float64 (JSON unmarshals numbers as float64)",
key, outputInt, expected,
)
}

if expectedIsFloat {
expectedInt = int(expectedFloat)
}

threshold := config.Thresholds.Int
if customThreshold, ok := config.Thresholds.CustomThresholds.Int[key]; ok {
threshold = customThreshold
Expand Down

0 comments on commit 002f36a

Please sign in to comment.