Skip to content

Commit 1ae5448

Browse files
committed
Fixed test to have better numeric conversions
1 parent 94525fa commit 1ae5448

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

test/api/basic_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ func TestRecords(t *testing.T) {
6060
Method: "GET",
6161
Query: "/table_records",
6262
Expected: `[
63-
{"name": "basic_positive", "int4": 1, "int8": 2, "float4": 1.2E3, "float8": 2.3, "numeric_val": 123.4567, "interval": "1 year 2 mons 6 days 00:07:00"},
64-
{"name": "basic_negative", "int4": -1, "int8": -50000000, "float4": -1.2, "float8": -2.34554, "numeric_val": -456.789, "interval": "3 mons 05:06:07"},
63+
{"name": "basic_positive", "int4": 1, "int8": 2, "float4": 1200, "float8": 2.3, "numeric_val": 123.4567, "interval": "1 year 2 mons 6 days 00:07:00"},
64+
{"name": "basic_negative", "int4": -1, "int8": -50000000, "float4": -1.2, "float8": -2.34554, "numeric_val": -456.7890, "interval": "3 mons 05:06:07"},
6565
{"name": "zero_values", "int4": 0, "int8": 0, "float4": 0, "float8": 0, "numeric_val": 0, "interval": ""},
66-
{"name": "high_precision", "int4": 2147483647, "int8": 9223372036854776000, "float4": 3.4028235e+38, "float8": 1.7976931348623157e+308, "numeric_val": 99999999999.9999, "interval": "999 days 23:59:59"},
67-
{"name": "small_decimals", "int4": 42, "int8": 12345, "float4": 0.001, "float8": 0.000001, "numeric_val": 0.0001, "interval": "00:00:01"},
68-
{"name": "financial_test", "int4": 1000, "int8": 1000000, "float4": 999.99, "float8": 1234567.89, "numeric_val": 12345.6789, "interval": "30 days"}
66+
{"name": "high_precision", "int4": 2147483647, "int8": 9223372036854775807, "float4": 3.4028235e+38, "float8": 1.7976931348623157e+308, "numeric_val": 99999999999.9999, "interval": "999 days 23:59:59"},
67+
{"name": "small_decimals", "int4": 42, "int8": 12345, "float4": 0.001, "float8": 1e-06, "numeric_val": 0.0001, "interval": "00:00:01"},
68+
{"name": "financial_test", "int4": 1000, "int8": 1000000, "float4": 999.99, "float8": 1.23456789e+06, "numeric_val": 12345.6789, "interval": "30 days"}
6969
]`,
7070
Status: 200,
7171
},

test/common.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package test
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"fmt"
67
"io"
@@ -126,9 +127,13 @@ func Execute(t *testing.T, config Config, tests []Test) {
126127
} else {
127128
var v1, v2 any
128129
var j1, j2 []byte
129-
_ = json.Unmarshal([]byte(test.Expected), &v1)
130+
d1 := json.NewDecoder(bytes.NewBuffer([]byte(test.Expected)))
131+
d1.UseNumber()
132+
d1.Decode(&v1)
130133
j1, _ = json.Marshal(v1)
131-
_ = json.Unmarshal(body, &v2)
134+
d2 := json.NewDecoder(bytes.NewBuffer(body))
135+
d2.UseNumber()
136+
d2.Decode(&v2)
132137
j2, _ = json.Marshal(v2)
133138
s1, s2 = string(j1), string(j2)
134139
}

0 commit comments

Comments
 (0)