From 005f3d0843d15e3d82bcdefc3d54a8bde10e2297 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Thu, 14 Dec 2023 18:51:05 +0000 Subject: [PATCH] chore(sqltest): Make it possible to enable/disable db container logs When running the sqltests, sometimes it is helpful to see the full database container logs, especially when there is an error in a migration or database setup. However, it also makes it difficult to see the test results. This adds a new variable to the makefile to easily toggle the output of these logs on or off. To run the tests without printing the dtabase logs use: DB_LOGS=0 make test To enable the logs use: DB_LOGS=1 make test By default the logs are not printed. --- internal/db/sqltest/Makefile | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/db/sqltest/Makefile b/internal/db/sqltest/Makefile index a5bdba6a2a..01779bdcb2 100644 --- a/internal/db/sqltest/Makefile +++ b/internal/db/sqltest/Makefile @@ -12,7 +12,6 @@ ifneq ($(strip $(SQL_TEST_DB_PORT)),) DOCKER_ARGS += -p $(SQL_TEST_DB_PORT):5432 endif - # Pass through options to pg_prove # See: https://pgtap.org/pg_prove.html PROVE_OPTS ?= @@ -47,6 +46,11 @@ PG_TAP_DOCKER_IMAGE := $(PG_TAP_DOCKER_IMAGE_BASE):$(PG_TAP_DOCKER_TAG) SQL_TEST_CONTAINER_NAME ?= boundary-sql-tests +log_cmd = true +DB_LOGS ?= 0 +ifeq ($(DB_LOGS), 1) + log_cmd = docker logs $(SQL_TEST_CONTAINER_NAME) +endif # re-write paths for docker dockerized_tests = $(patsubst tests/%,/test/%,$(TESTS)) @@ -74,7 +78,7 @@ test: -e TESTS="$(PROVE_OPTS) $(dockerized_tests)" \ -v "$(CWD)/tests":/test \ $(PG_TAP_DOCKER_IMAGE); \ - (ret=$$?; docker stop $(SQL_TEST_CONTAINER_NAME) &>/dev/null && docker logs $(SQL_TEST_CONTAINER_NAME) && docker rm -v $(SQL_TEST_CONTAINER_NAME) &>/dev/null && exit $$ret) + (ret=$$?; docker stop $(SQL_TEST_CONTAINER_NAME) > /dev/null 2>&1 && $(log_cmd) && docker rm -f -v $(SQL_TEST_CONTAINER_NAME) > /dev/null 2>&1 && exit $$ret) database-up: @echo Using $(POSTGRES_DOCKER_IMAGE)