tooling: add test commands to Makefile

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4787
GitOrigin-RevId: 6fef3933dbc414ddc79f0f738e91e28bee4b8c4f
This commit is contained in:
Daniel Harvey 2022-06-20 14:33:04 +01:00 committed by hasura-bot
parent dd5198d0ba
commit 4cd4eda81c
2 changed files with 88 additions and 0 deletions

View File

@ -1,3 +1,5 @@
include Makefile.tests
# skip contrib with its generated .hs file because it doesn't
# come with a cabal file, which can trigger a bug in ormolu
HS_FILES = $(shell git ls-files '*.hs' '*.hs-boot' | grep -v '^contrib/')
@ -127,3 +129,5 @@ lint: lint-hs lint-shell check-format
.PHONY: lint-changed
lint-changed: lint-hs-changed lint-shell-changed check-format-changed

84
Makefile.tests Normal file
View File

@ -0,0 +1,84 @@
# scripts used in CI to wait for DBs to be ready
DB_UTILS = ./.buildkite/scripts/util/util.sh
# the following variables are set up in Docker Compose
# and are also defined in Harness.Constants for use in hspec tests
PG_PORT = 65002
PG_DBNAME = "hasura"
PG_DBUSER = "hasura"
PG_DBPASSWORD = "hasura"
MYSQL_PORT = 65001
MYSQL_DBNAME = "hasura"
MYSQL_DBUSER = "hasura"
MYSQL_DBPASSWORD = "hasura"
MSSQL_PORT = 65003
MSSQL_DBNAME = "hasura"
MSSQL_DBUSER = "hasura"
MSSQL_DBPASSWORD = "Hasura1!"
CITUS_PORT = 65004
.PHONY: start-postgres
## start-postgres: start local postgres DB in Docker and wait for it to be ready
start-postgres:
docker-compose up -d postgres
$(DB_UTILS) wait_for_postgres $(PG_PORT)
$(DB_UTILS) wait_for_postgres_db $(PG_PORT) "$(PG_DBNAME)" "$(PG_DBUSER)" "$(PG_DBPASSWORD)"
.PHONY: start-citus
## start-citus: start local citus DB in Docker and wait for it to be ready
start-citus:
docker-compose up -d citus
$(DB_UTILS) wait_for_postgres $(CITUS_PORT)
$(DB_UTILS) wait_for_postgres_db $(CITUS_PORT) "$(PG_DBNAME)" "$(PG_DBUSER)" "$(PG_DBPASSWORD)"
.PHONY: start-sqlserver
## start-sqlserver: start local sqlserver DB in Docker and wait for it to be ready
start-sqlserver:
docker-compose up -d sqlserver
$(DB_UTILS) wait_for_mssql $(MSSQL_PORT)
$(DB_UTILS) wait_for_mssql_db $(MSSQL_PORT) "$(MSSQL_DBNAME)" "$(MSSQL_DBUSER)" "$(MSSQL_DBPASSWORD)"
.PHONY: start-mysql
## start-mysql: start local mariaDB in Docker and wait for it to be ready
start-mysql:
docker-compose up -d mariadb
$(DB_UTILS) wait_for_mysql $(MYSQL_PORT) "$(MYSQL_DBNAME)" "$(MYSQL_DBUSER)" "$(MYSQL_DBPASSWORD)"
# there isn't a wait_for_mysql_db that does an actual query yet, so just give
# it a bit of time to wake up
sleep 10
.PHONY: start-backends
## start-backends: start postgres/mysql/mssql and wait for them to be ready
start-backends: start-postgres start-sqlserver start-mysql start-citus
.PHONY: test-bigquery
## test-bigquery: run tests for BigQuery backend
test-bigquery:
# will require some setup detailed here: https://github.com/hasura/graphql-engine-mono/tree/main/server/tests-hspec#required-setup-for-bigquery-tests
cabal run tests-hspec -- -m "BigQuery"
.PHONY: test-sqlserver
## test-sqlserver: run tests for SQL Server backend
test-sqlserver: start-postgres start-sqlserver
# run tests
cabal run tests-hspec -- -m "SQLServer"
# stop docker
docker-compose down -v
.PHONY: test-mysql
## test-mysql: run tests for MySQL backend
test-mysql: start-postgres start-mysql
# run tests
cabal run tests-hspec -- -m "MySQL"
# stop docker
docker-compose down -v
.PHONY: test-backends
## test-backends: run tests for all backends
test-backends: start-backends
# big query tests will require some setup detailed here: https://github.com/hasura/graphql-engine-mono/tree/main/server/tests-hspec#required-setup-for-bigquery-tests
# run tests
cabal run tests-hspec
# stop docker
docker-compose down -v