Serialize binary bytea cols into hex/base64 (#537)

- Adds binary serialization into hex/base64
- Default codec is base64
- Codec can be changed via `--binary-codec` CLI option
This commit is contained in:
Dan Sosedoff
2021-12-29 11:03:50 -06:00
committed by GitHub
parent 1323012cff
commit 706caa44bf
8 changed files with 159 additions and 32 deletions

View File

@@ -7,33 +7,52 @@ import (
"github.com/stretchr/testify/assert"
)
func Test_PrepareBigints(t *testing.T) {
result := Result{
Columns: []string{"value"},
Rows: []Row{
Row{int(1234)},
Row{int64(9223372036854775807)},
Row{int64(-9223372036854775808)},
Row{float64(9223372036854775808.9223372036854775808)},
Row{float64(999999999999999.9)},
},
}
func TestPostProcess(t *testing.T) {
t.Run("large numbers", func(t *testing.T) {
result := Result{
Columns: []string{"value"},
Rows: []Row{
{int(1234)},
{int64(9223372036854775807)},
{int64(-9223372036854775808)},
{float64(9223372036854775808.9223372036854775808)},
{float64(999999999999999.9)},
},
}
result.PrepareBigints()
result.PostProcess()
assert.Equal(t, 1234, result.Rows[0][0])
assert.Equal(t, "9223372036854775807", result.Rows[1][0])
assert.Equal(t, "-9223372036854775808", result.Rows[2][0])
assert.Equal(t, "9.223372036854776e+18", result.Rows[3][0])
assert.Equal(t, "9.999999999999999e+14", result.Rows[4][0])
assert.Equal(t, 1234, result.Rows[0][0])
assert.Equal(t, "9223372036854775807", result.Rows[1][0])
assert.Equal(t, "-9223372036854775808", result.Rows[2][0])
assert.Equal(t, "9.223372036854776e+18", result.Rows[3][0])
assert.Equal(t, "9.999999999999999e+14", result.Rows[4][0])
})
t.Run("binary encoding", func(t *testing.T) {
result := Result{
Columns: []string{"data"},
Rows: []Row{
{"text value"},
{"text with symbols !@#$%"},
{string([]byte{10, 11, 12, 13})},
},
}
result.PostProcess()
assert.Equal(t, "text value", result.Rows[0][0])
assert.Equal(t, "text with symbols !@#$%", result.Rows[1][0])
assert.Equal(t, "CgsMDQ==", result.Rows[2][0])
})
}
func Test_CSV(t *testing.T) {
func TestCSV(t *testing.T) {
result := Result{
Columns: []string{"id", "name", "email"},
Rows: []Row{
Row{1, "John", "john@example.com"},
Row{2, "Bob", "bob@example.com"},
{1, "John", "john@example.com"},
{2, "Bob", "bob@example.com"},
},
}
@@ -43,12 +62,12 @@ func Test_CSV(t *testing.T) {
assert.Equal(t, expected, output)
}
func Test_JSON(t *testing.T) {
func TestJSON(t *testing.T) {
result := Result{
Columns: []string{"id", "name", "email"},
Rows: []Row{
Row{1, "John", "john@example.com"},
Row{2, "Bob", "bob@example.com"},
{1, "John", "john@example.com"},
{2, "Bob", "bob@example.com"},
},
}