Created
October 14, 2025 10:27
-
-
Save kavirajk/0125d22231303d860b3e1ad4064683e5 to your computer and use it in GitHub Desktop.
default_http_compression_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package code | |
| import ( | |
| "context" | |
| "testing" | |
| "time" | |
| "github.com/ClickHouse/clickhouse-go/v2" | |
| "github.com/stretchr/testify/require" | |
| ) | |
| func TestDefaultHTTPCompress(t *testing.T) { | |
| ctx := context.Background() | |
| conn := clickhouse.OpenDB(&clickhouse.Options{ | |
| MaxOpenConns: 8, | |
| Addr: []string{"localhost:8123"}, | |
| Protocol: clickhouse.HTTP, | |
| // Debug: true, | |
| Compression: &clickhouse.Compression{ | |
| Method: clickhouse.CompressionGZIP, | |
| }, | |
| }) | |
| require.NoError(t, conn.Ping()) | |
| _, err := conn.Exec(`DROP TABLE IF EXISTS example`) | |
| require.NoError(t, err) | |
| const ddl = ` | |
| CREATE TABLE example ( | |
| Col1 UInt64 | |
| , Col2 String | |
| , Col3 Array(UInt8) | |
| , Col4 DateTime | |
| ) ENGINE = Memory | |
| ` | |
| _, err = conn.Exec(ddl) | |
| require.NoError(t, err) | |
| for i := 0; i < 100; i++ { | |
| _, err := conn.Exec(`INSERT INTO example VALUES (?, ?, ?, now())`, i, "Golang", []uint8{1, 2, 4}) | |
| require.NoError(t, err) | |
| } | |
| row := conn.QueryRow(`SELECT * FROM example WHERE Col1=99`) | |
| var ( | |
| col1 uint64 | |
| col2 string | |
| col3 []uint8 | |
| col4 time.Time | |
| ) | |
| err = row.Scan(&col1, &col2, &col3, &col4) | |
| require.NoError(t, err) | |
| conn2, err := clickhouse.Open(&clickhouse.Options{ | |
| MaxOpenConns: 8, | |
| Addr: []string{"localhost:8123"}, | |
| Protocol: clickhouse.HTTP, | |
| // Debug: true, | |
| }) | |
| if err != nil { | |
| panic(err) | |
| } | |
| require.NoError(t, conn2.Ping(ctx)) | |
| row2 := conn2.QueryRow(ctx, `SELECT * FROM example WHERE Col1=99`) | |
| err = row2.Scan(&col1, &col2, &col3, &col4) | |
| require.NoError(t, err) | |
| } |
Author
kavirajk
commented
Oct 14, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment