|
| 1 | +# Run Tests From coretest Locally |
| 2 | + |
| 3 | +## Run a Single Test |
| 4 | + |
| 5 | +If you have a single coretest that you want to run, for example: `src/test/unit_tests/test_s3_bucket_policy.js`. |
| 6 | +The options for running it are: NC deployment (no DB) and containerized deployment (with DB) |
| 7 | + |
| 8 | +### A) NC deployment (No DB) |
| 9 | +Run simply with `sudo NC_CORETEST=true node ./node_modules/mocha/bin/mocha .src/test/unit_tests/test_s3_bucket_policy.js` |
| 10 | +More info can be found in [CI & Tests](#ci--tests). |
| 11 | + |
| 12 | +### B) Containerized deployment (With DB) |
| 13 | +One way is to run it with: `make run-single-test testname=test_s3_bucket_policy.js` |
| 14 | +but it would take time to build the needed images, therefore we will focus on another way. |
| 15 | + |
| 16 | +Another way is to create a postgres container and then run the test with the following steps: |
| 17 | + |
| 18 | +#### First Tab - Run the Container |
| 19 | +1. Pull postgres image version 15: |
| 20 | +`docker pull quay.io/sclorg/postgresql-15-c9s` |
| 21 | +- We use postgres with version 15. |
| 22 | +- `c9s` is for CentOS Stream 9. |
| 23 | +2. Run the postgres container with this image: |
| 24 | +`docker run -p 5432:5432 -e POSTGRESQL_ADMIN_PASSWORD=noobaa quay.io/sclorg/postgresql-15-c9s` |
| 25 | +- Port 5432 is the port for docker. |
| 26 | +- We added the env `POSTGRESQL_ADMIN_PASSWORD=noobaa` to match the default password, you can find in postgres client ([reference](https://github.com/noobaa/noobaa-core/blob/12847927fc3cde52c4ab0098da41de3ced1fc63a/src/util/postgres_client.js#L1480)). |
| 27 | + |
| 28 | +expect to see output that starts with: |
| 29 | +``` |
| 30 | +The files belonging to this database system will be owned by user "postgres". |
| 31 | +This user must also own the server process. |
| 32 | +``` |
| 33 | +and ends with: |
| 34 | +``` |
| 35 | +Starting server... |
| 36 | +2025-03-05 13:43:57.600 UTC [1] LOG: redirecting log output to logging collector process |
| 37 | +2025-03-05 13:43:57.600 UTC [1] HINT: Future log output will appear in directory "log" |
| 38 | +``` |
| 39 | + |
| 40 | +### Second Tab - Run the Test |
| 41 | +3. Run the test: |
| 42 | +- If you run on Rancher Desktop: |
| 43 | +3.1. Run with: `./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` |
| 44 | +(by default it is connected to 127.0.0.1). |
| 45 | +- If you run on minikube: |
| 46 | +3.1. Take the address to connect to docker inside minikube: `minikube ip` |
| 47 | +3.2. Run with: |
| 48 | +`POSTGRES_HOST=<output of minikube ip> ./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` |
| 49 | + |
| 50 | +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. |
| 51 | +Another option, which is less recommended, is to connect to postgres container and drop the tables with: |
| 52 | +- If you run on Rancher Desktop: |
| 53 | +`psql -h 127.0.0.1 -p 5432 -U postgres postgres` |
| 54 | +- If you run on minikube: |
| 55 | +`psql -h <output of minikube ip> -p 5432 -U postgres postgres` |
| 56 | +- And Then: `DROP DATABASE coretest;` |
| 57 | + |
| 58 | +Notes: |
| 59 | +* For running `psql` commands you would need to install it on your machine (better with the matching version of postgres). |
| 60 | +* In case you already run postgres on your machine (not the mentioned container) it might raise some issues, better remove it (in MacOs using the Activity Monitor and search for postgres). |
| 61 | +* In case a test failed with "error: database "coretest" already exists" it means that you probably forgot to drop the DB table, and you can stop (ctrl + c) and rerun the `docker run` command mentioned above and then run the test again. |
| 62 | +* If you want to run the test with higher debug level you can add the `NOOBAA_LOG_LEVEL=all`, for example: `NOOBAA_LOG_LEVEL=all ./node_modules/mocha/bin/mocha.js src/test/unit_tests/test_s3_bucket_policy.js` (notice that you can printings that are not only from `LOG`, `L0`, `WARN` and `ERROR`, for example: `L1`, `L2`, `L3`, etc.) |
| 63 | + |
| 64 | +## Run All Tests |
| 65 | + |
| 66 | +If you want to run all the mocha tests using the DB on the second tab you can simply run `npm test`. |
0 commit comments