Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Separate DB for tests (#4362)
Browse files Browse the repository at this point in the history
* Changes for xrengine test db

* Moved test env to individual scripts
  • Loading branch information
hanzlamateen authored Dec 4, 2021
1 parent 558e10b commit cd78837
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .env.local.default
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ MYSQL_DATABASE=xrengine
MYSQL_HOST=127.0.0.1
MYSQL_PORT=3306
MYSQL_URL=

MYSQL_TEST_USER=server
MYSQL_TEST_PASSWORD=password
MYSQL_TEST_DATABASE=xrengine
MYSQL_TEST_HOST=127.0.0.1
MYSQL_TEST_PORT=3305
MYSQL_TEST_URL=
# --------------------------------


Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@
"dev-reinit-windows": "cd packages/server && npm run dev-reinit-db-windows",
"dev-nginx": "",
"cleanup-tests": "node tests/cleanup-tests.js",
"pretest": "cross-env TEST=true npm run dev-reinit",
"test": "npm run test:projects && npm run test:packages",
"test:e2e": "mocha",
"test:packages": "c8 lerna run test",
"test:projects": "c8 lerna run test:projects",
"test:packages": "cross-env TEST=true c8 lerna run test",
"test:projects": "cross-env TEST=true c8 lerna run test:projects",
"test:ci": "cpy --no-overwrite --rename=.env.local '.env.local.default' . && cross-env CI=true npm run test",
"lint": "prettier --check \"packages/**/*.{ts,tsx}\"",
"format": "prettier --write \"packages/**/*.{ts,tsx}\"",
Expand Down
16 changes: 10 additions & 6 deletions packages/server-core/src/appconfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import url from 'url'
import '@xrengine/engine/src/patchEngineNode'

const kubernetesEnabled = process.env.KUBERNETES === 'true'
const testEnabled = process.env.TEST === 'true'

if (globalThis.process?.env.APP_ENV === 'development') {
var fs = require('fs')
Expand All @@ -27,11 +28,11 @@ if (!kubernetesEnabled) {
* Database
*/
export const db = {
username: process.env.MYSQL_USER!,
password: process.env.MYSQL_PASSWORD!,
database: process.env.MYSQL_DATABASE!,
host: process.env.MYSQL_HOST!,
port: process.env.MYSQL_PORT!,
username: testEnabled ? process.env.MYSQL_TEST_USER! : process.env.MYSQL_USER!,
password: testEnabled ? process.env.MYSQL_TEST_PASSWORD! : process.env.MYSQL_PASSWORD!,
database: testEnabled ? process.env.MYSQL_TEST_DATABASE! : process.env.MYSQL_DATABASE!,
host: testEnabled ? process.env.MYSQL_TEST_HOST! : process.env.MYSQL_HOST!,
port: testEnabled ? process.env.MYSQL_TEST_PORT! : process.env.MYSQL_PORT!,
dialect: 'mysql',
forceRefresh: process.env.FORCE_DB_REFRESH === 'true',
url: '',
Expand All @@ -41,7 +42,10 @@ export const db = {
max: parseInt(process.env.SEQUELIZE_POOL_MAX || '5')
}
}
db.url = process.env.MYSQL_URL || `mysql://${db.username}:${db.password}@${db.host}:${db.port}/${db.database}`

db.url =
(testEnabled ? process.env.MYSQL_TEST_URL : process.env.MYSQL_URL) ||
`mysql://${db.username}:${db.password}@${db.host}:${db.port}/${db.database}`

/**
* Server / backend
Expand Down
10 changes: 10 additions & 0 deletions scripts/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ services:
MYSQL_PASSWORD: password
ports:
- '3306:3306'
testdb:
image: mariadb:10.7
container_name: xrengine_test_db
environment:
MYSQL_ROOT_PASSWORD: xrengine-root-pa$$w0rd
MYSQL_DATABASE: xrengine
MYSQL_USER: server
MYSQL_PASSWORD: password
ports:
- '3305:3306'
redis:
image: redis
container_name: xrengine_redis
Expand Down

0 comments on commit cd78837

Please sign in to comment.