Skip to content

Commit

Permalink
extend test to include complex reflected type
Browse files Browse the repository at this point in the history
  • Loading branch information
SpencerTorres committed Nov 21, 2024
1 parent fbf6c16 commit f152bef
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/variant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestVariant(t *testing.T) {

const ddl = `
CREATE TABLE IF NOT EXISTS test_variant (
c Variant(Array(UInt8), Bool, Int64, String)
c Variant(Array(Map(String, String)), Array(UInt8), Bool, Int64, String)
) Engine = MergeTree() ORDER BY tuple()
`
require.NoError(t, conn.Exec(ctx, ddl))
Expand All @@ -52,11 +52,13 @@ func TestVariant(t *testing.T) {
require.NoError(t, batch.Append(chcol.NewVariantWithType("test", "String")))
require.NoError(t, batch.Append(true))
require.NoError(t, batch.Append(chcol.NewVariant([]uint8{0xA, 0xB, 0xC}).WithType("Array(UInt8)")))
require.NoError(t, batch.Append([]map[string]string{{"key1": "value1", "key2": "value2"}, {"key3": "value3"}}))
require.NoError(t, batch.Append(nil))
require.NoError(t, batch.Append(84))
require.NoError(t, batch.Append(chcol.NewVariantWithType("test2", "String")))
require.NoError(t, batch.Append(true))
require.NoError(t, batch.Append(chcol.NewVariant([]uint8{0xD, 0xE, 0xF}).WithType("Array(UInt8)")))
require.NoError(t, batch.Append([]map[string]string{{"key1": "value1", "key2": "value2"}, {"key3": "value3"}}))
require.NoError(t, batch.Send())

rows, err := conn.Query(ctx, "SELECT c from test_variant")
Expand Down Expand Up @@ -84,6 +86,11 @@ func TestVariant(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []uint8{0xA, 0xB, 0xC}, row.Any().([]uint8))

require.True(t, rows.Next())
err = rows.Scan(&row)
require.NoError(t, err)
require.Equal(t, []map[string]string{{"key1": "value1", "key2": "value2"}, {"key3": "value3"}}, row.Any())

require.True(t, rows.Next())
err = rows.Scan(&row)
require.NoError(t, err)
Expand Down Expand Up @@ -113,4 +120,10 @@ func TestVariant(t *testing.T) {
require.NoError(t, err)
require.Equal(t, []uint8{0xD, 0xE, 0xF}, u8s)

var arrStrMap []map[string]string
require.True(t, rows.Next())
err = rows.Scan(&arrStrMap)
require.NoError(t, err)
require.Equal(t, []map[string]string{{"key1": "value1", "key2": "value2"}, {"key3": "value3"}}, arrStrMap)

}

0 comments on commit f152bef

Please sign in to comment.