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.
pull/4445/head
Timothy Messier 2 years ago
parent e51d0e0b4f
commit 005f3d0843
No known key found for this signature in database
GPG Key ID: EFD2F184F7600572

@ -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)

Loading…
Cancel
Save