Skip to content

Commit

Permalink
fix(test): run repository tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
jvallesm committed Dec 2, 2024
1 parent 49d7528 commit 6d64244
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
12 changes: 6 additions & 6 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ ONNX_MODEL_FOLDER_PATH=${PWD}/pkg/component/resources/onnx

# test

# TEST_DBHOST and TEST_DBNAME are used to initialize a separate database for
# coverage tests. In general, test queries will be run within a transaction
# that will be rolled back on cleanup, but there might be cases where this
# isn't possible (e.g. lock tests). We want to keep these queries isolated from
# the main database.
TEST_DBHOST=localhost
# TEST_DBNAME is used to initialize a separate database for coverage tests. In
# general, test queries will be run within a transaction that will be rolled
# back on cleanup, but there might be cases where this isn't possible (e.g.
# lock tests). We want to keep these queries isolated from the main database.
# Tests will be run within a container that will need access to the database,
# so it is assumed that the database host is available at localhost:5432.
TEST_DBNAME=pipeline_test
20 changes: 13 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
include .env
export

GOTEST_FLAGS := CFG_DATABASE_HOST=${TEST_DBHOST} CFG_DATABASE_NAME=${TEST_DBNAME}

#============================================================================

.PHONY: dev
Expand Down Expand Up @@ -65,19 +63,27 @@ go-gen: ## Generate codes

.PHONY: dbtest-pre
dbtest-pre:
@${GOTEST_FLAGS} go run ./cmd/migration
@# Requires a local running instance of PostgreSQL at localhost:5432
@CFG_DATABASE_NAME=${TEST_DBNAME} CFG_DATABASE_HOST=localhost go run ./cmd/migration

.PHONY: coverage
coverage: ## Generate coverage report
@if [ "${DBTEST}" = "true" ]; then make dbtest-pre; fi
@docker run --rm \
@TAGS=$$([ "${DBTEST}" = "true" ] && echo "dbtest"); \
if [ -n "$$TAGS" ]; then \
echo "Running coverage with tags: $$TAGS"; \
else \
echo "Running standard coverage"; \
fi; \
docker run --rm \
-v $(PWD):/${SERVICE_NAME} \
-e GOTEST_FLAGS="${GOTEST_FLAGS}" \
-e CFG_DATABASE_HOST=host.docker.internal \
-e CFG_DATABASE_NAME=${TEST_DBNAME} \
--user $(id -u):$(id -g) \
--entrypoint= \
instill/${SERVICE_NAME}:dev \
go test -v -race ${GOTEST_TAGS} -coverpkg=./... -coverprofile=coverage.out -covermode=atomic -timeout 30m ./...
@if [ "${HTML}" = "true" ]; then \
go test -v -race $$([ -n "$$TAGS" ] && echo "-tags=$$TAGS") -coverpkg=./... -coverprofile=coverage.out -covermode=atomic -timeout 30m ./...; \
if [ "${HTML}" = "true" ]; then \
docker run --rm \
-v $(PWD):/${SERVICE_NAME} \
--user $(id -u):$(id -g) \
Expand Down

0 comments on commit 6d64244

Please sign in to comment.