mysql-client-tests: Write script/README for running node tests without installing everything

This commit is contained in:
Taylor Bantle
2023-03-08 13:35:32 -08:00
parent a7b6797be7
commit 13968d62f4
4 changed files with 87 additions and 34 deletions

View File

@@ -0,0 +1,41 @@
setup_dolt_repo() {
REPO_NAME="dolt_repo_$$"
mkdir $REPO_NAME
cd $REPO_NAME
dolt init
dolt sql -q "CREATE TABLE mysqldump_table(pk int)"
dolt sql -q "INSERT INTO mysqldump_table VALUES (1);"
dolt sql -q "CREATE TABLE warehouse(warehouse_id int primary key, warehouse_name longtext)"
dolt sql -q "INSERT into warehouse VALUES (1, 'UPS'), (2, 'TV'), (3, 'Table');"
PORT=$( definePORT )
USER="dolt"
dolt sql-server --host 0.0.0.0 --port=$PORT --user=$USER --loglevel=trace &
SERVER_PID=$!
# Give the server a chance to start
sleep 1
export MYSQL_PWD=""
}
teardown_dolt_repo() {
kill $SERVER_PID
rm -rf $REPO_NAME
}
definePORT() {
getPORT=""
for i in {0..9}
do
let getPORT="($$ + $i) % (65536-1024) + 1024"
portinuse=$(lsof -i -P -n | grep LISTEN | grep $attemptedPORT | wc -l)
if [ $portinuse -eq 0 ]
then
echo "$getPORT"
break
fi
done
}

View File

@@ -1,3 +1,6 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helpers.bash
# MySQL client tests are set up to test Dolt as a MySQL server and
# standard MySQL Clients in a wide array of languages. I used BATS because
# it was easy to set up the Dolt piece using the command line.
@@ -8,31 +11,12 @@
# gotchas, we can add tests for that specific language.
setup() {
REPO_NAME="dolt_repo_$$"
mkdir $REPO_NAME
cd $REPO_NAME
dolt init
dolt sql -q "CREATE TABLE mysqldump_table(pk int)"
dolt sql -q "INSERT INTO mysqldump_table VALUES (1);"
dolt sql -q "CREATE TABLE warehouse(warehouse_id int primary key, warehouse_name longtext)"
dolt sql -q "INSERT into warehouse VALUES (1, 'UPS'), (2, 'TV'), (3, 'Table');"
PORT=$( definePORT )
USER="dolt"
dolt sql-server --host 0.0.0.0 --port=$PORT --user=$USER --loglevel=trace &
SERVER_PID=$!
# Give the server a chance to start
sleep 1
export MYSQL_PWD=""
setup_dolt_repo
}
teardown() {
cd ..
kill $SERVER_PID
rm -rf $REPO_NAME
teardown_dolt_repo
# Check if postgresql is still running. If so stop it
active=$(service postgresql status)
@@ -172,16 +156,4 @@ EOF" -m "postgres"
Rscript $BATS_TEST_DIRNAME/r/rmariadb-test.r $USER $PORT $REPO_NAME
}
definePORT() {
getPORT=""
for i in {0..9}
do
let getPORT="($$ + $i) % (65536-1024) + 1024"
portinuse=$(lsof -i -P -n | grep LISTEN | grep $attemptedPORT | wc -l)
if [ $portinuse -eq 0 ]
then
echo "$getPORT"
break
fi
done
}

View File

@@ -0,0 +1,32 @@
# Node Client Integration Tests
## Install
```
$ npm install
```
## Run node tests
To run the node tests, you must make sure you have Dolt installed on your computer and
have run `npm install`. Then update your Dolt config by running:
```shell
sh ../mysql-client-tests-entrypoint.sh
```
And then you can run the tests using the `run-tests.sh` script, which sets up the database, runs the SQL server, runs the provided `.js` test file against the running server, and then tears down the database.
For example, you can run the `workbench.js` tests by running:
```shell
sh run-tests.sh workbench.js
```
## Workbench stability tests
The tests in `workbenchTests` were written to enforce the stability of the SQL workbench
on [Hosted](https://hosted.doltdb.com/). The workbench uses many Dolt system tables,
functions, and procedures, and any changes to these interfaces can break the workbench.
@tbantle22 will be tagged in any GitHub PR that updates those files to ensure appropriate
workbench updates are made for Dolt changes that break these queries.

View File

@@ -0,0 +1,8 @@
#!/bin/sh
source ../helpers.bash
echo "Running $1 tests"
setup_dolt_repo
cd ..
node $1 $USER $PORT $REPO_NAME
teardown_dolt_repo