Consider improving error messaging for knownvalue.NumberExact
float comparisons
#311
Labels
documentation
Improvements or additions to documentation
terraform-plugin-testing version
Use cases
When using
knownvalue.NumberExact
, it's possible to get confusing error messages in the situation where the provided*big.Float
does not match the value parsed from ajson.Number
because of the mantissa using something likebig.NewFloat
.Example
Test error
What can make this more confusing is when it accidentally is correct and the test passes 😅 :
Workaround
You can workaround this by creating the
*big.Float
exactly how the internal state check logic/Terraform creates it. Fixing the initial example in this issue:Proposal
Improve the error message to also include the precision/rounding/mantissa information to make it more apparent why two floating point numbers don't match. Perhaps we could also make a suggestion about how best to create the
*big.Float
value if a comparison doesn't match because of the mantissa.References
The text was updated successfully, but these errors were encountered: