Skip to content
Snippets Groups Projects
Commit ecc73ab0 authored by Federico Hurtado's avatar Federico Hurtado
Browse files

Set up docker container for testing and fix issues of server being ready before sql.

parent e63dae39
No related branches found
No related tags found
1 merge request!11Basic functionality achieved of generalized search function. Need to define...
......@@ -29,7 +29,7 @@ docker push container.cs.vt.edu/fhurtado14/corps-directory/frontend:latest
Go to CS Launch and scale down backend deployment to 0, then scale back up to 1.
# Steps to create a branch and merge request on git lab
# Steps to create a branch and merge request on git lab
To make a branch do: git checkout -b Branch-Name
......@@ -39,8 +39,13 @@ To push your local changes to remote git: git push --set-upstream origin Branch-
To merge go to GitLab. Click merge request tab. Click new merge request. Fill out the information. Assign to members if you want branch to be tested before merged. They will have to approve your branch in order for it to be merged. Make sure you check "delete source branch when merge request is accepted" and "squash commits when merge request is accepted."
If you are assigned a merge-request you can view them on the merge-request tab on GitLab. You will have to switch to their branch by doing git checkout Branch-Name to test their branch. Note: You can only switch to their branch if you have pulled in an up to date main branch. For example let's say I did a "git push --set-upstream origin test-branch" so it could connect with git. If I did that after you last pulled, then you won't be able to switch into it until you git pull again.
If you are assigned a merge-request you can view them on the merge-request tab on GitLab. You will have to switch to their branch by doing git checkout Branch-Name to test their branch. Note: You can only switch to their branch if you have pulled in an up to date main branch. For example let's say I did a "git push --set-upstream origin test-branch" so it could connect with git. If I did that after you last pulled, then you won't be able to switch into it until you git pull again.
After merge happens:
Switch back to main: git checkout main
Pull changes from remote repository: git pull origin main
# Integration tests
docker-compose -f docker-compose.test.yml up --build
docker-compose -f docker-compose.test.yml down -v --remove-orphans
......@@ -10,10 +10,14 @@ require("dotenv").config();
// Initialize the pool instance to read the SQL startup file
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
database: process.env.DB_NAME,
password: process.env.DB_PASSWORD,
host: process.env.NODE_ENV === "test" ? "test-mysql" : process.env.DB_HOST,
user: process.env.NODE_ENV === "test" ? "test_user" : process.env.DB_USER,
database:
process.env.NODE_ENV === "test"
? "corps_directory_test_db"
: process.env.DB_NAME,
password:
process.env.NODE_ENV === "test" ? "test_password" : process.env.DB_PASSWORD,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0,
......
......@@ -415,6 +415,11 @@ class DatabaseInitializer {
console.log("database init completed.");
}
async initializeTestDB() {
const schemaPath = path.join(__dirname, "./schema.sql");
await this.executeSQLFile(schemaPath);
}
}
module.exports = DatabaseInitializer;
services:
test-backend:
build: ./backend
environment:
- NODE_ENV=test
- DB_HOST=test-mysql
- DB_USER=test_user
- DB_PASSWORD=test_password
- DB_NAME=corps_directory_test_db
depends_on:
test-mysql:
condition: service_healthy
command: ["sh", "-c", "npm test"]
test-mysql:
image: mysql:8.0
environment:
MYSQL_ROOT_PASSWORD: test_root_password
MYSQL_DATABASE: corps_directory_test_db
MYSQL_USER: test_user
MYSQL_PASSWORD: test_password
ports:
- "3307:3306" # Map to a different port to avoid conflicts
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
......@@ -8,7 +8,8 @@ services:
volumes:
- ./backend:/app
depends_on:
- mysql
mysql:
condition: service_healthy
environment:
DB_HOST: mysql
DB_USER: corps_directory_dev
......@@ -36,6 +37,11 @@ services:
MYSQL_PASSWORD: corps_db_password
volumes:
- db_data:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 5
volumes:
db_data:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment