diff --git a/scripts/make/test-infrastructure.mk b/scripts/make/test-infrastructure.mk index 4f4af37994b..4956d39c818 100644 --- a/scripts/make/test-infrastructure.mk +++ b/scripts/make/test-infrastructure.mk @@ -30,6 +30,21 @@ DOCKER_COMPOSE = $(error "Could not find docker-compose.") endif endif +ifneq ($(shell command -v sqlcmd),) +MSSQL_SQLCMD = sqlcmd +MSSQL_SQLCMD_PORT = $(MSSQL_PORT) +else +ifneq ($(shell [[ -e /opt/mssql-tools/bin/sqlcmd ]] && echo true),) +MSSQL_SQLCMD = /opt/mssql-tools/bin/sqlcmd +MSSQL_SQLCMD_PORT = $(MSSQL_PORT) +else +MSSQL_SQLCMD = docker exec $(shell basename $(PWD))-sqlserver-1 sqlcmd +MSSQL_SQLCMD_PORT = 1433 +endif +endif + +export MSSQL_SQLCMD + define stop_after @ echo $1 >&2 @ $1 || EXIT_STATUS=$$?; \ @@ -43,34 +58,72 @@ endef .PHONY: start-postgres ## start-postgres: start local PostgreSQL DB in Docker and wait for it to be ready -start-postgres: +start-postgres: spawn-postgres wait-for-postgres + +.PHONY: spawn-postgres +spawn-postgres: $(DOCKER_COMPOSE) up -d postgres + +.PHONY: wait-for-postgres +wait-for-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: +start-citus: spawn-citus wait-for-citus + +.PHONY: spawn-citus +spawn-citus: $(DOCKER_COMPOSE) up -d citus + +.PHONY: wait-for-citus +wait-for-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 MS SQL Server DB in Docker and wait for it to be ready -start-sqlserver: +start-sqlserver: spawn-sqlserver wait-for-sqlserver + +.PHONY: spawn-sqlserver +spawn-sqlserver: $(DOCKER_COMPOSE) up -d sqlserver + +.PHONY: wait-for-sqlserver +wait-for-sqlserver: $(DB_UTILS) wait_for_mssql $(MSSQL_PORT) - $(DB_UTILS) wait_for_mssql_db $(MSSQL_PORT) "$(MSSQL_DBNAME)" "$(MSSQL_DBUSER)" "$(MSSQL_DBPASSWORD)" + $(DB_UTILS) wait_for_mssql_db $(MSSQL_SQLCMD_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: +start-mysql: spawn-mysql wait-for-mysql + +.PHONY: spawn-mysql +spawn-mysql: $(DOCKER_COMPOSE) up -d mariadb + +.PHONY: wait-for-mysql +wait-for-mysql: $(DB_UTILS) wait_for_mysql $(MYSQL_PORT) "$(MYSQL_DBNAME)" "$(MYSQL_DBUSER)" "$(MYSQL_DBPASSWORD)" +.PHONY: start-dc-reference-agent +## start-mysql: start the Data Connectors reference agent in Docker and wait for it to be ready +start-dc-reference-agent: spawn-dc-reference-agent wait-for-dc-reference-agent + +.PHONY: spawn-dc-reference-agent +spawn-dc-reference-agent: + $(DOCKER_COMPOSE) up -d dc-reference-agent + +# This target is probably unncessary, but there to follow the pattern. +.PHONY: wait-for-dc-reference-agent +wait-for-dc-reference-agent: + .PHONY: start-backends ## start-backends: start local PostgreSQL, MariaDB, and MS SQL Server in Docker and wait for them to be ready -start-backends: start-postgres start-sqlserver start-mysql start-citus +start-backends: \ + spawn-postgres spawn-sqlserver spawn-mysql spawn-citus spawn-dc-reference-agent \ + wait-for-postgres wait-for-sqlserver wait-for-mysql wait-for-citus wait-for-dc-reference-agent .PHONY: stop-everything ## stop-everything: tear down test databases diff --git a/scripts/make/tests.mk b/scripts/make/tests.mk index 77b287c93e9..196c394f7ef 100644 --- a/scripts/make/tests.mk +++ b/scripts/make/tests.mk @@ -7,13 +7,13 @@ test-bigquery: start-postgres remove-tix-file .PHONY: test-sqlserver ## test-sqlserver: run tests for SQL Server backend -test-sqlserver: start-postgres start-sqlserver remove-tix-file +test-sqlserver: spawn-postgres spawn-sqlserver wait-for-postgres wait-for-sqlserver remove-tix-file $(call stop_after, \ cabal run tests-hspec -- -m 'SQLServer') .PHONY: test-mysql ## test-mysql: run tests for MySQL backend -test-mysql: start-postgres start-mysql remove-tix-file +test-mysql: spawn-postgres spawn-mysql wait-for-postgres wait-for-mysql remove-tix-file $(call stop_after, \ cabal run tests-hspec -- -m 'MySQL')