@@ -1200,6 +1200,132 @@ def cockroachdb_connection(cockroachdb_db: str) -> str:
12001200 cleanup_connection (connection_name )
12011201
12021202
1203+ # =============================================================================
1204+ # Turso (libSQL) Fixtures
1205+ # =============================================================================
1206+
1207+ # Turso connection settings for Docker (libsql-server)
1208+ TURSO_HOST = os .environ .get ("TURSO_HOST" , "localhost" )
1209+ TURSO_PORT = int (os .environ .get ("TURSO_PORT" , "8081" ))
1210+
1211+
1212+ def turso_available () -> bool :
1213+ """Check if Turso (libsql-server) is available."""
1214+ return is_port_open (TURSO_HOST , TURSO_PORT )
1215+
1216+
1217+ @pytest .fixture (scope = "session" )
1218+ def turso_server_ready () -> bool :
1219+ """Check if Turso is ready and return True/False."""
1220+ if not turso_available ():
1221+ return False
1222+
1223+ # Wait a bit for libsql-server to be fully ready
1224+ time .sleep (1 )
1225+ return True
1226+
1227+
1228+ @pytest .fixture (scope = "function" )
1229+ def turso_db (turso_server_ready : bool ) -> str :
1230+ """Set up Turso test database."""
1231+ if not turso_server_ready :
1232+ pytest .skip ("Turso (libsql-server) is not available" )
1233+
1234+ try :
1235+ from libsql_client import create_client_sync
1236+ except ImportError :
1237+ pytest .skip ("libsql-client is not installed" )
1238+
1239+ turso_url = f"http://{ TURSO_HOST } :{ TURSO_PORT } "
1240+
1241+ try :
1242+ client = create_client_sync (turso_url )
1243+
1244+ # Drop tables if they exist and recreate
1245+ client .execute ("DROP TABLE IF EXISTS test_users" )
1246+ client .execute ("DROP TABLE IF EXISTS test_products" )
1247+ client .execute ("DROP VIEW IF EXISTS test_user_emails" )
1248+
1249+ # Create test tables
1250+ client .execute ("""
1251+ CREATE TABLE test_users (
1252+ id INTEGER PRIMARY KEY,
1253+ name TEXT NOT NULL,
1254+ email TEXT UNIQUE
1255+ )
1256+ """ )
1257+
1258+ client .execute ("""
1259+ CREATE TABLE test_products (
1260+ id INTEGER PRIMARY KEY,
1261+ name TEXT NOT NULL,
1262+ price REAL NOT NULL,
1263+ stock INTEGER DEFAULT 0
1264+ )
1265+ """ )
1266+
1267+ # Create test view
1268+ client .execute ("""
1269+ CREATE VIEW test_user_emails AS
1270+ SELECT id, name, email FROM test_users WHERE email IS NOT NULL
1271+ """ )
1272+
1273+ # Insert test data
1274+ client .execute ("""
1275+ INSERT INTO test_users (id, name, email) VALUES
1276+ (1, 'Alice', 'alice@example.com'),
1277+ (2, 'Bob', 'bob@example.com'),
1278+ (3, 'Charlie', 'charlie@example.com')
1279+ """ )
1280+
1281+ client .execute ("""
1282+ INSERT INTO test_products (id, name, price, stock) VALUES
1283+ (1, 'Widget', 9.99, 100),
1284+ (2, 'Gadget', 19.99, 50),
1285+ (3, 'Gizmo', 29.99, 25)
1286+ """ )
1287+
1288+ client .close ()
1289+
1290+ except Exception as e :
1291+ pytest .skip (f"Failed to setup Turso database: { e } " )
1292+
1293+ yield turso_url
1294+
1295+ # Cleanup: drop test tables
1296+ try :
1297+ client = create_client_sync (turso_url )
1298+ client .execute ("DROP TABLE IF EXISTS test_users" )
1299+ client .execute ("DROP TABLE IF EXISTS test_products" )
1300+ client .execute ("DROP VIEW IF EXISTS test_user_emails" )
1301+ client .close ()
1302+ except Exception :
1303+ pass
1304+
1305+
1306+ @pytest .fixture (scope = "function" )
1307+ def turso_connection (turso_db : str ) -> str :
1308+ """Create a sqlit CLI connection for Turso and clean up after test."""
1309+ connection_name = f"test_turso_{ os .getpid ()} "
1310+
1311+ # Clean up any existing connection with this name
1312+ cleanup_connection (connection_name )
1313+
1314+ # Create the connection (no auth token needed for local libsql-server)
1315+ run_cli (
1316+ "connection" , "create" ,
1317+ "--name" , connection_name ,
1318+ "--db-type" , "turso" ,
1319+ "--server" , turso_db ,
1320+ "--password" , "" , # No auth token for local server
1321+ )
1322+
1323+ yield connection_name
1324+
1325+ # Cleanup
1326+ cleanup_connection (connection_name )
1327+
1328+
12031329# =============================================================================
12041330# SSH Tunnel Fixtures
12051331# =============================================================================
@@ -1210,7 +1336,7 @@ def cockroachdb_connection(cockroachdb_db: str) -> str:
12101336SSH_USER = os .environ .get ("SSH_USER" , "testuser" )
12111337SSH_PASSWORD = os .environ .get ("SSH_PASSWORD" , "testpass" )
12121338# The PostgreSQL host as seen from the SSH server (docker network)
1213- SSH_REMOTE_DB_HOST = os .environ .get ("SSH_REMOTE_DB_HOST" , "postgres" )
1339+ SSH_REMOTE_DB_HOST = os .environ .get ("SSH_REMOTE_DB_HOST" , "postgres-ssh " )
12141340SSH_REMOTE_DB_PORT = int (os .environ .get ("SSH_REMOTE_DB_PORT" , "5432" ))
12151341
12161342
@@ -1240,9 +1366,12 @@ def ssh_postgres_db(ssh_server_ready: bool) -> str:
12401366 pytest .skip ("psycopg2 is not installed" )
12411367
12421368 # Connect directly to PostgreSQL to set up test data
1243- # In CI, PostgreSQL is accessible directly on the host
1369+ # postgres-ssh container is accessible on port 5433
12441370 pg_host = os .environ .get ("SSH_DIRECT_PG_HOST" , "localhost" )
12451371 pg_port = int (os .environ .get ("SSH_DIRECT_PG_PORT" , "5433" ))
1372+ pg_user = POSTGRES_USER
1373+ pg_password = POSTGRES_PASSWORD
1374+ pg_database = POSTGRES_DATABASE
12461375
12471376 try :
12481377 conn = psycopg2 .connect (
0 commit comments