From fed0c70f69c7d76366a993cae845b4e012e88577 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Fri, 5 Jul 2024 18:33:29 -0300 Subject: [PATCH] feat: only run tests with Postgres if ALLOW_TO_USE_DATABASE_URL is set to true --- src/test.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/test.ts b/src/test.ts index ae2af52a..e6967596 100644 --- a/src/test.ts +++ b/src/test.ts @@ -79,7 +79,7 @@ export async function getTestDB() { export const createTestDB = async (databaseUrl?: string) => { databaseUrl ??= Deno.env.get('DATABASE_URL') ?? 'sqlite://:memory:'; - const dialect: 'sqlite' | 'postgres' = (() => { + let dialect: 'sqlite' | 'postgres' = (() => { const protocol = databaseUrl.split(':')[0]; switch (protocol) { case 'sqlite': @@ -93,6 +93,15 @@ export const createTestDB = async (databaseUrl?: string) => { } })(); + const allowToUseDATABASE_URL = Deno.env.get('ALLOW_TO_USE_DATABASE_URL')?.toLowerCase() ?? ''; + if (allowToUseDATABASE_URL !== 'true' && dialect === 'postgres') { + console.warn( + '%cRunning tests with sqlite, if you meant to use Postgres, run again with ALLOW_TO_USE_DATABASE_URL environment variable set to true', + 'color: yellow;', + ); + dialect = 'sqlite'; + } + let kysely: Kysely; if (dialect === 'sqlite') {