docker: create a database "test" for ClickHouse

Keep using the default one for the migration tests, but for the small
tests, use the "test" one.
This commit is contained in:
Vincent Bernat
2025-07-12 17:03:22 +02:00
parent ac68c5970e
commit 85226d0326
6 changed files with 16 additions and 10 deletions

View File

@@ -67,6 +67,7 @@ func TestInsertMemory(t *testing.T) {
conn, err := ch.Dial(ctx, ch.Options{
Address: server,
Database: "test",
DialTimeout: 100 * time.Millisecond,
Settings: []ch.Setting{
{Key: "allow_suspicious_low_cardinality_types", Value: "1"},
@@ -78,7 +79,7 @@ func TestInsertMemory(t *testing.T) {
// Create the table
q := fmt.Sprintf(
`CREATE OR REPLACE TABLE test_table_insert (%s) ENGINE = Memory`,
`CREATE OR REPLACE TABLE test_schema_insert (%s) ENGINE = Memory`,
c.ClickHouseCreateTable(schema.ClickHouseSkipAliasedColumns, schema.ClickHouseSkipGeneratedColumns),
)
t.Logf("Query: %s", q)
@@ -91,7 +92,7 @@ func TestInsertMemory(t *testing.T) {
// Insert
input := bf.ClickHouseProtoInput()
if err := conn.Do(ctx, ch.Query{
Body: input.Into("test_table_insert"),
Body: input.Into("test_schema_insert"),
Input: input,
OnInput: func(ctx context.Context) error {
bf.Clear()
@@ -106,13 +107,16 @@ func TestInsertMemory(t *testing.T) {
{
conn, err := clickhouse.Open(&clickhouse.Options{
Addr: []string{server},
Auth: clickhouse.Auth{
Database: "test",
},
DialTimeout: 100 * time.Millisecond,
})
if err != nil {
t.Fatalf("clickhouse.Open() error:\n%+v", err)
}
// Use formatRow to get JSON representation
rows, err := conn.Query(ctx, "SELECT formatRow('JSONEachRow', *) FROM test_table_insert ORDER BY TimeReceived")
rows, err := conn.Query(ctx, "SELECT formatRow('JSONEachRow', *) FROM test_schema_insert ORDER BY TimeReceived")
if err != nil {
t.Fatalf("clickhouse.Query() error:\n%+v", err)
}

View File

@@ -0,0 +1 @@
CREATE DATABASE IF NOT EXISTS test;

View File

@@ -124,11 +124,13 @@ services:
- zookeeper
environment:
- CLICKHOUSE_SKIP_USER_SETUP=1
- CLICKHOUSE_ALWAYS_RUN_INITDB_SCRIPTS=1
cap_add:
- SYS_NICE
volumes:
- ./clickhouse/cluster.xml:/etc/clickhouse-server/config.d/cluster.xml
- ./clickhouse/cluster-1.xml:/etc/clickhouse-server/config.d/cluster-1.xml
- ./clickhouse/test-db.sql:/docker-entrypoint-initdb.d/test-db.sql
ports:
- 127.0.0.1:8123:8123/tcp
- 127.0.0.1:9000:9000/tcp

View File

@@ -118,9 +118,6 @@ func isOldTable(schema *schema.Component, table string) bool {
if strings.Contains(table, schema.ClickHouseHash()) {
return false
}
if strings.HasPrefix(table, "test_") {
return true
}
oldSuffixes := []string{
"_raw",
"_raw_consumer",

View File

@@ -22,6 +22,7 @@ func TestInsertMemory(t *testing.T) {
conn, err := ch.Dial(ctx, ch.Options{
Address: server,
Database: "test",
DialTimeout: 100 * time.Millisecond,
})
if err != nil {
@@ -29,7 +30,7 @@ func TestInsertMemory(t *testing.T) {
}
if err := conn.Do(ctx, ch.Query{
Body: `CREATE OR REPLACE TABLE test_table_insert
Body: `CREATE OR REPLACE TABLE test_example_insert
(
ts DateTime64(9),
severity_text Enum8('INFO'=1, 'DEBUG'=2),
@@ -81,7 +82,7 @@ func TestInsertMemory(t *testing.T) {
// Insert single data block.
if err := conn.Do(ctx, ch.Query{
Body: "INSERT INTO test_table_insert VALUES",
Body: "INSERT INTO test_example_insert VALUES",
Input: input,
}); err != nil {
t.Fatalf("Do() error:\n%+v", err)
@@ -92,7 +93,7 @@ func TestInsertMemory(t *testing.T) {
// Stream data to ClickHouse server in multiple data blocks.
var blocks int
if err := conn.Do(ctx, ch.Query{
Body: input.Into("test_table_insert"), // helper that generates INSERT INTO query with all columns
Body: input.Into("test_example_insert"), // helper that generates INSERT INTO query with all columns
Input: input,
// OnInput is called to prepare Input data before encoding and sending

View File

@@ -33,6 +33,7 @@ func TestInsert(t *testing.T) {
// Create components
dbConf := clickhousedb.DefaultConfiguration()
dbConf.Servers = []string{server}
dbConf.Database = "test"
dbConf.DialTimeout = 100 * time.Millisecond
chdb, err := clickhousedb.New(r, dbConf, clickhousedb.Dependencies{
Daemon: daemon.NewMock(t),