Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Jun 17, 2024
1 parent b6ebed4 commit c1190eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/debezium/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func EncodeDecimal(value string, scale int) ([]byte, error) {
bigFloatValue := new(big.Float)
if _, success := bigFloatValue.SetString(value); !success {
return nil, fmt.Errorf("unable to use '%s' as a floating-point number", value)
return nil, fmt.Errorf("unable to use %q as a floating-point number", value)
}

scaledValue := big.NewFloat(math.Pow(10, float64(scale)))
Expand All @@ -21,7 +21,7 @@ func EncodeDecimal(value string, scale int) ([]byte, error) {
// Extract the scaled integer value.
bigIntValue := new(big.Int)
if _, success := bigIntValue.SetString(bigFloatValue.String(), 10); !success {
return nil, fmt.Errorf("unable to use '%s' as a floating-point number", value)
return nil, fmt.Errorf("unable to use %q as a floating-point number", value)
}

data := bigIntValue.Bytes()
Expand Down
9 changes: 7 additions & 2 deletions lib/debezium/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,20 @@ func TestEncodeDecimal(t *testing.T) {
value: "6408.355",
scale: 3,
},
{
name: "total",
value: "1.05",
scale: 2,
},
{
name: "malformed - empty string",
value: "",
expectedErr: "unable to use '' as a floating-point number",
expectedErr: `unable to use "" as a floating-point number`,
},
{
name: "malformed - not a floating-point",
value: "abcdefg",
expectedErr: "unable to use 'abcdefg' as a floating-point number",
expectedErr: `unable to use "abcdefg" as a floating-point number`,
},
}

Expand Down

0 comments on commit c1190eb

Please sign in to comment.