From 976129dbbcc0e67bd7b1afb84261f61729919210 Mon Sep 17 00:00:00 2001 From: apeng-singlestore <127370261+apeng-singlestore@users.noreply.github.com> Date: Thu, 29 Aug 2024 10:58:34 -0700 Subject: [PATCH] rewrite init.sql for each docker container --- .../tests/singlestore/singlestore-common.ts | 17 ++++++++++++----- .../tests/singlestore/test/init.sql | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/integration-tests/tests/singlestore/singlestore-common.ts b/integration-tests/tests/singlestore/singlestore-common.ts index 3810481fb..104064d7e 100644 --- a/integration-tests/tests/singlestore/singlestore-common.ts +++ b/integration-tests/tests/singlestore/singlestore-common.ts @@ -72,10 +72,8 @@ import type { Equal } from '~/utils.ts'; import path from 'path'; import { fileURLToPath } from 'url'; +import fs from 'fs'; -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); -const initSqlPath = path.resolve(__dirname, 'test/init.sql'); type TestSingleStoreDB = SingleStoreDatabase; @@ -192,17 +190,26 @@ const citiesMySchemaTable = mySchema.table('cities', { name: text('name').notNull(), }); + + let singlestoreContainer: Docker.Container; export async function createDockerDB(): Promise<{ connectionString: string; container: Docker.Container }> { const docker = new Docker(); const port = await getPort({ port: 3306 }); const image = 'ghcr.io/singlestore-labs/singlestoredb-dev:latest'; + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + const initSqlPath = path.resolve(__dirname, 'test/init.sql'); + const initSqlContent = `CREATE DATABASE drizzle;`; + fs.writeFileSync(initSqlPath, initSqlContent, { encoding: 'utf8' }); + const pullStream = await docker.pull(image); await new Promise((resolve, reject) => docker.modem.followProgress(pullStream, (err) => (err ? reject(err) : resolve(err))) ); + singlestoreContainer = await docker.createContainer({ Image: image, Env: ['ROOT_PASSWORD=singlestore'], @@ -217,10 +224,10 @@ export async function createDockerDB(): Promise<{ connectionString: string; cont }); await singlestoreContainer.start(); - await new Promise((resolve) => setTimeout(resolve, 5000)); + await new Promise((resolve) => setTimeout(resolve, 7000)); return { - connectionString: `singlestore://root:singlestore@127.0.0.1:${port}/drizzle`, + connectionString: `singlestore://root:singlestore@localhost:${port}/drizzle`, container: singlestoreContainer, }; } diff --git a/integration-tests/tests/singlestore/test/init.sql b/integration-tests/tests/singlestore/test/init.sql index 014f83c7e..1adb86baa 100644 --- a/integration-tests/tests/singlestore/test/init.sql +++ b/integration-tests/tests/singlestore/test/init.sql @@ -1 +1 @@ -CREATE database drizzle; \ No newline at end of file +CREATE DATABASE drizzle; \ No newline at end of file