Automates DB reset and migrations when unit and integration tests are run

This commit is contained in:
Andrew J Yao
2019-10-28 21:35:45 -07:00
committed by yaoandrew
parent 25f9c6c9e3
commit 722f7f3665
5 changed files with 30 additions and 15 deletions
+18 -1
View File
@@ -41,16 +41,34 @@ metalint: | $(METALINT)
lint:
$(LINT) $$($(PKGS)) | grep -v -E "exported (function)|(var)|(method)|(type).*should have comment or be unexported"
#Test
TEST_DB = vulcanize_testing
TEST_CONNECT_STRING = postgresql://localhost:5432/$(TEST_DB)?sslmode=disable
.PHONY: test
test: | $(GINKGO) $(LINT)
go vet ./...
go fmt ./...
dropdb --if-exists $(TEST_DB)
createdb $(TEST_DB)
cd db/migrations;\
$(GOOSE) postgres "$(TEST_CONNECT_STRING)" up
cd db/migrations/;\
$(GOOSE) postgres "$(TEST_CONNECT_STRING)" reset
make migrate NAME=$(TEST_DB)
$(GINKGO) -r --skipPackage=integration_tests,integration
.PHONY: integrationtest
integrationtest: | $(GINKGO) $(LINT)
go vet ./...
go fmt ./...
dropdb --if-exists $(TEST_DB)
createdb $(TEST_DB)
cd db/migrations;\
$(GOOSE) postgres "$(TEST_CONNECT_STRING)" up
cd db/migrations/;\
$(GOOSE) postgres "$(TEST_CONNECT_STRING)" reset
make migrate NAME=$(TEST_DB)
$(GINKGO) -r integration_test/
build:
@@ -71,7 +89,6 @@ checkdbvars:
test -n "$(HOST_NAME)" # $$HOST_NAME
test -n "$(PORT)" # $$PORT
test -n "$(NAME)" # $$NAME
test -n "$(USER)" # $$USER
@echo $(CONNECT_STRING)
## Check that the migration variable (id/timestamp) is provided