From ab8ad1bb42a641014ce8184397ce78fb7b380b87 Mon Sep 17 00:00:00 2001 From: Kat Yang <69819079+yangkb09@users.noreply.github.com> Date: Tue, 19 Jul 2022 04:04:38 -0400 Subject: [PATCH] Chore: Add new go test commands for unit, integration, and pro tests to makefile (#51202) * Chore: Add new go test commands for unit, integration tests to makefile * Add test-go-unit and test-go-integration targets as dependencies of the test-go target * Add makefile target for mysql & postgres backends * Set GRAFANA_TEST_DB variable for the xargs postgres command Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Set GRAFANA_TEST_DB variable for the xargs mysql command Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Use postgres_tests as source Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Set postgres_tests as source Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> * Clean test cache before postgres and mysql integration test makefile commands Co-authored-by: Sofia Papagiannaki <1632407+papagian@users.noreply.github.com> --- Makefile | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 262dc3e3458..1279a7ae45c 100644 --- a/Makefile +++ b/Makefile @@ -94,9 +94,30 @@ run-frontend: deps-js ## Fetch js dependencies and watch frontend for rebuild ##@ Testing -test-go: ## Run tests for backend. - @echo "test backend" - $(GO) test -v ./pkg/... +.PHONY: test-go +test-go: test-go-unit test-go-integration + +.PHONY: test-go-unit +test-go-unit: ## Run unit tests for backend with flags. + @echo "test backend unit tests" + $(GO) test -short -covermode=atomic -timeout=30m ./pkg/... + +.PHONY: test-go-integration +test-go-integration: ## Run integration tests for backend with flags. + @echo "test backend integration tests" + $(GO) test -run Integration -covermode=atomic -timeout=30m ./pkg/... + +.PHONY: test-go-integration-postgres +test-go-integration-postgres: devenv-postgres ## Run integration tests for postgres backend with flags. + @echo "test backend integration postgres tests" + $(GO) clean -testcache + $(GO) list './pkg/...' | xargs -I {} sh -c 'GRAFANA_TEST_DB=postgres go test -run Integration -covermode=atomic -timeout=30m {}' + +.PHONY: test-go-integration-mysql +test-go-integration-mysql: devenv-mysql ## Run integration tests for mysql backend with flags. + @echo "test backend integration mysql tests" + $(GO) clean -testcache + $(GO) list './pkg/...' | xargs -I {} sh -c 'GRAFANA_TEST_DB=mysql go test -run Integration -covermode=atomic -timeout=30m {}' test-js: ## Run tests for frontend. @echo "test frontend" @@ -153,6 +174,14 @@ devenv-down: ## Stop optional services. test -f docker-compose.yaml && \ docker-compose down || exit 0; +devenv-postgres: + @cd devenv; \ + sources=postgres_tests + +devenv-mysql: + @cd devenv; \ + sources=mysql_tests + ##@ Helpers # We separate the protobuf generation because most development tasks on