From 3c0c5b24fc6c20472a2fcafbfb7e86e01c567838 Mon Sep 17 00:00:00 2001 From: Manuel Carrer Date: Fri, 8 Nov 2024 18:53:16 +0100 Subject: [PATCH] Switch to justfile --- integration_tests/Makefile | 38 ------------------------------------- integration_tests/README.md | 15 +++++++-------- justfile | 36 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 46 deletions(-) delete mode 100644 integration_tests/Makefile create mode 100644 justfile diff --git a/integration_tests/Makefile b/integration_tests/Makefile deleted file mode 100644 index 363d8a4..0000000 --- a/integration_tests/Makefile +++ /dev/null @@ -1,38 +0,0 @@ -# Basically the same as defining all targets .PHONY -MAKEFLAGS += --always-make - -unit_tests: - cargo build --workspace --tests - cargo test --no-fail-fast --workspace --exclude lard_tests -- --nocapture - -test_all: --test_all clean ---test_all: setup - cargo test --workspace --no-fail-fast -- --nocapture --test-threads=1 - -end_to_end: --end_to_end clean ---end_to_end: setup - cargo test --test end_to_end --no-fail-fast -- --nocapture --test-threads=1 - -debug_kafka: --kafka clean ---kafka: setup - cargo test --test end_to_end test_kafka --features debug --no-fail-fast -- --nocapture --test-threads=1 - -# With the `debug` feature, the database is not cleaned up after running the test, -# so it can be inspected with psql. Run with: -# TEST= make debug_test -debug_test: setup - cargo test "$(TEST)" --features debug --no-fail-fast -- --nocapture --test-threads=1 - -setup: - @echo "Starting Postgres docker container..." - docker run --name lard_tests -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres - @echo; sleep 5 - cargo build --workspace --tests - @echo; echo "Loading DB schema..."; echo - @cd ..; target/debug/prepare_postgres - -clean: - @echo "Stopping Postgres container..." - docker stop lard_tests - @echo "Removing Postgres container..." - docker rm lard_tests diff --git a/integration_tests/README.md b/integration_tests/README.md index fa585df..21e482b 100644 --- a/integration_tests/README.md +++ b/integration_tests/README.md @@ -20,22 +20,21 @@ End-to-end tests are implemented inside `integration_tests\tests\end_to_end.rs`. > defined in the `mock_permit_tables` function, otherwise the ingestor will not be able to > insert the data into the database. -If you have Docker installed, you can run the tests locally using the provided -`Makefile`: +If you have Docker installed, you can run the tests locally using the provided `justfile`: ```terminal # Run all tests -make test_all +just test_all # Run unit tests only -make unit_tests +just test_unit # Run integration tests only -make end_to_end +just test_end_to_end -# Debug a specific test (does not clean up the DB if `my_test_name` is an integration test) -TEST=my_test_name make debug_test +# Debug a specific test (does not clean up the DB if `test_name` is an integration test) +just debug_test test_name # If any error occurs while running integration tests, you might need to reset the DB container manually -make clean +just clean ``` diff --git a/justfile b/justfile new file mode 100644 index 0000000..9e111a0 --- /dev/null +++ b/justfile @@ -0,0 +1,36 @@ +test_unit: + cargo build --workspace --tests + cargo test --no-fail-fast --workspace --exclude lard_tests -- --nocapture + +test_all: setup && clean + cargo test --workspace --no-fail-fast -- --nocapture --test-threads=1 + +test_end_to_end: setup && clean + cargo test --test end_to_end --no-fail-fast -- --nocapture --test-threads=1 + +test_migrations: debug_migrations && clean + +# Debug commands don't perfom the clean up action after running. +# This allows to manually check the state of the database. +debug_kafka: setup + cargo test --test end_to_end test_kafka --features debug --no-fail-fast -- --nocapture --test-threads=1 + +debug_test TEST: setup + cargo test {{TEST}} --features debug --no-fail-fast -- --nocapture --test-threads=1 + +debug_migrations: setup + @ cd migrations && go test -v ./... + +setup: + @ echo "Starting Postgres docker container..." + docker run --name lard_tests -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres + @ echo; sleep 5 + cargo build --workspace --tests + @ echo; echo "Loading DB schema..."; echo + @target/debug/prepare_postgres + +clean: + @ echo "Stopping Postgres container..." + docker stop lard_tests + @ echo "Removing Postgres container..." + docker rm lard_tests