First pass on a basic smoke test for the Prisma ORM. Reproduces the issue from: https://github.com/dolthub/dolt/issues/4511

This commit is contained in:
Jason Fulghum
2022-10-27 18:42:34 -07:00
parent 7f3d52317e
commit a27dc9a065
8 changed files with 156 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
FROM --platform=linux/amd64 ubuntu:18.04
# install peewee
# install ORM tools and dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt update -y && \
apt install -y \
@@ -10,6 +10,7 @@ RUN apt update -y && \
curl -sL https://deb.nodesource.com/setup_14.x | bash - && \
apt update -y && \
apt install -y \
nodejs \
python3.8 \
python3-pip \
git \

View File

@@ -9,9 +9,9 @@ should pass given those interactions.
This is meant to be more declarative and more robust than using `bats` for
these integration tests.
Something belongs in this package if it primarly tests interactions with the
Something belongs in this package if it primarily tests interactions with the
exposed MySQL port on the sql-server.
Something belongs in `bats` if it primarly tests interactions with the `dolt`
Something belongs in `bats` if it primarily tests interactions with the `dolt`
binary itself. One example for the `dolt sql-server` command itself would be
testing config validation which results in exit codes or help text displayed.

View File

@@ -1,18 +1,20 @@
## ORM Client Tests
Different ORMs come with test packages that run against a standard MySQL database. These
tests run an ORM's test suite against Dolt to continously test MySQL
capabilities.
These tests verify that various ORM libraries that support MySQL are compatible with Dolt. Ideally,
we use the same test suite that the ORM provides to test their support with MySQL, but in some
cases we may start with a smaller smoke test to get some quick, initial coverage.
These tests can be run locally using Docker. From the root directory of this
repo, run:
These tests can be run locally using Docker. Before you can build the image, you also need to copy the go folder
into the integration-tests folder; unfortunately just symlinking doesn't seem to work. From the
integration-tests directory of the dolt repo, run:
```bash
$ docker build -t orm-tests -f ORMDockerfile
$ cp -r ../go .
$ docker build -t orm-tests -f ORMDockerfile .
$ docker run orm-tests:latest
```
Running the containter should produce output like:
Running the container should produce output like:
```bash
Updating dolt config for tests:
@@ -23,4 +25,9 @@ Config successfully updated.
Running orm-tests:
1..1
not ok 1 peewee client test
```
```
### Future ORM Libraries to Test
- typeorm
- mikro-orm
- hibernate

View File

@@ -5,35 +5,61 @@ setup() {
mkdir $REPO_NAME
cd $REPO_NAME
dolt init
PORT=$( definePORT )
USER="dolt"
dolt sql-server --host 0.0.0.0 --port=$PORT --user=$USER --loglevel=trace &
dolt sql-server --host 0.0.0.0 --user=$USER --loglevel=trace &
SERVER_PID=$!
# Give the server a chance to start
sleep 1
export MYSQL_PWD=""
cd ..
}
teardown() {
cd ..
kill $SERVER_PID
rm -rf $REPO_NAME
rm -f /tmp/mysql.sock
}
@test "peewee client test" {
# Peewee is a lightweight ORM library for Python applications
@test "peewee ORM test suite" {
skip "Dolt does not pass all tests yet"
# peewee tests require the test database to be named peewee_test
mysql -h 0.0.0.0 -u $USER --port=$PORT -e "CREATE DATABASE IF NOT EXISTS peewee_test"
mysql -h 0.0.0.0 -u $USER -e "CREATE DATABASE IF NOT EXISTS peewee_test"
# Setup and install pewee
git clone https://github.com/coleifer/peewee
cd peewee
python3 setup.py install
python3 runtests.py -e mysql --mysql-host=0.0.0.0 --mysql-port=$PORT --mysql-user=$USER --mysql-password=""
python3 runtests.py -e mysql --mysql-host=0.0.0.0 --mysql-user=$USER --mysql-password=""
}
# Prisma is an ORM for Node/TypeScript applications. This is a simple smoke test to make sure
# Dolt can support the most basic Prisma operation.
@test "prisma ORM smoke test" {
mysql --protocol TCP -u dolt -e "create database obsidian;"
cd prisma
npm install
npx -c "prisma migrate dev --name init"
}
@test "prisma ORM test suite" {
skip "Not implemented yet"
# More info on running Prisma's tests here:
# https://github.com/prisma/prisma/blob/main/TESTING.md
#
# The MySQL integration tests for Prisma
# https://github.com/prisma/prisma/tree/main/packages/integration-tests/src/__tests__/integration/mysql
}
# Turn this test on to prevent the container from exiting if you need to exec a shell into
# the container to debug failed tests.
#@test "Pause container for an hour to debug failures" {
# sleep 3600
#}

View File

@@ -0,0 +1,26 @@
{
"name": "prisma-dolt-smoketest",
"version": "0.0.0",
"author": {
"name": "DoltHub",
"email": "dolthub@dolthub.com"
},
"publisher": "dolthub",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
},
"dependencies": {
"@prisma/client": "^4.4.0",
"prisma": "^4.4.0"
},
"devDependencies": {
"@types/node": "^17.0.23"
},
"publishConfig": {
"access": "restricted"
}
}

View File

@@ -0,0 +1,51 @@
lockfileVersion: 5.4
specifiers:
'@prisma/client': ^4.4.0
'@types/node': ^17.0.23
prisma: ^4.4.0
dependencies:
'@prisma/client': 4.4.0_prisma@4.4.0
prisma: 4.4.0
devDependencies:
'@types/node': 17.0.45
packages:
/@prisma/client/4.4.0_prisma@4.4.0:
resolution: {integrity: sha512-ciKOP246x1xwr04G9ajHlJ4pkmtu9Q6esVyqVBO0QJihaKQIUvbPjClp17IsRJyxqNpFm4ScbOc/s9DUzKHINQ==}
engines: {node: '>=14.17'}
requiresBuild: true
peerDependencies:
prisma: '*'
peerDependenciesMeta:
prisma:
optional: true
dependencies:
'@prisma/engines-version': 4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6
prisma: 4.4.0
dev: false
/@prisma/engines-version/4.4.0-66.f352a33b70356f46311da8b00d83386dd9f145d6:
resolution: {integrity: sha512-P5v/PuEIJLYXZUZBvOLPqoyCW+m6StNqHdiR6te++gYVODpPdLakks5HVx3JaZIY+LwR02juJWFlwpc9Eog/ug==}
dev: false
/@prisma/engines/4.4.0:
resolution: {integrity: sha512-Fpykccxlt9MHrAs/QpPGpI2nOiRxuLA+LiApgA59ibbf24YICZIMWd3SI2YD+q0IAIso0jCGiHhirAIbxK3RyQ==}
requiresBuild: true
dev: false
/@types/node/17.0.45:
resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==}
dev: true
/prisma/4.4.0:
resolution: {integrity: sha512-l/QKLmLcKJQFuc+X02LyICo0NWTUVaNNZ00jKJBqwDyhwMAhboD1FWwYV50rkH4Wls0RviAJSFzkC2ZrfawpfA==}
engines: {node: '>=14.17'}
hasBin: true
requiresBuild: true
dependencies:
'@prisma/engines': 4.4.0
dev: false

View File

@@ -0,0 +1,15 @@
datasource db {
provider = "mysql"
url = "mysql://dolt@localhost:1122/obsidian"
}
model Sample {
id Int @id @default(autoincrement())
cleanBath String
cleanKitchen String
date DateTime
}
generator client {
provider = "prisma-client-js"
}

View File

@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"outDir": "dist",
"strict": true,
"types": [
"node"
],
"paths": {}
},
}