diff --git a/docs/dev_guide/run_coretest_locally.md b/docs/dev_guide/run_coretest_locally.md new file mode 100644 index 0000000000..0305417ac7 --- /dev/null +++ b/docs/dev_guide/run_coretest_locally.md @@ -0,0 +1,56 @@ +# Run a Single Test From coretest Locally + +If you have a single coretest that you want to run, for example: `src/test/unit_tests/test_s3_bucket_policy.js`. +The options for running it are: NC deployment (no DB) and containerized deployment (with DB) + +## 1) NC deployment (No DB) +Run simply with `sudo NC_CORETEST=true node ./node_modules/mocha/bin/mocha .src/test/unit_tests/test_s3_bucket_policy.js` +More info can be found in [CI & Tests](#ci--tests). + +## 2) Containerized deployment (With DB) +One way is to run it with: `make run-single-test testname=test_s3_bucket_policy.js` +but it would take time to build the needed images, therefore we will focus on another way. + +Another way is to create a postgres container and then run the test with the following steps: + +### First Tab - Run the Container +1. Pull postgres image version 15: +`docker pull quay.io/sclorg/postgresql-15-c9s` +- We use postgres with version 15. +- `c9s` is for CentOS Stream 9. +2. Run the postgres container with this image: +`docker run -p 5432:5432 -e POSTGRESQL_ADMIN_PASSWORD=noobaa quay.io/sclorg/postgresql-15-c9s` +- Port 5432 is the port for docker. +- We added the env `POSTGRESQL_ADMIN_PASSWORD=noobaa` to match the default password we you can find in postgres client ([reference](https://github.com/noobaa/noobaa-core/blob/12847927fc3cde52c4ab0098da41de3ced1fc63a/src/util/postgres_client.js#L1480)). + +expect to see output that starts with: +``` +The files belonging to this database system will be owned by user "postgres". +This user must also own the server process. +``` +and ends with: +``` +Starting server... +2025-03-05 13:43:57.600 UTC [1] LOG: redirecting log output to logging collector process +2025-03-05 13:43:57.600 UTC [1] HINT: Future log output will appear in directory "log" +``` + +## Second Tab - Run the Test +3. Run the test: +- If you run on Rancher Desktop: +3.1. Run with: `./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` +(by default it is connected to 127.0.0.1). +- If you run on minikube: +3.1. Take the address to connect to docker inside minikube: `minikube ip` +3.2. Run with: +`POSTGRES_HOST= ./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` + +If you want to rerun the test after code changes you can easily run `ctrl + c` in the first tab (to stop and remove the container) and then run it again. +Another option, which is less recommended, is to connect to postgres container and drop the tables with: +- If you run on Rancher Desktop: +`psql -h 127.0.0.1 -p 5432 -U postgres postgres` +- If you run on minikube: +`psql -h -p 5432 -U postgres postgres` +- And Then: `DROP DATABASE coretest;` + +