Skip to content

Commit

Permalink
build: Cleanup Makefile
Browse files Browse the repository at this point in the history
Draws a boundary between each Driver implementation in the test suite.
The goal is to have less assumptions about the host: it should be able
to build the code, but doesn't need a working postgres and/or mysql
installation to get most of the way there. Testing the code against a
live DB is recommended, but it's separated now.
  • Loading branch information
rafaelespinoza committed Apr 18, 2021
1 parent 5bd0958 commit 6ba4d3e
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,31 @@ define LDFLAGS
-X $(PKG_IMPORT_PATH)/internal/version.Tag=$(shell git describe --tag)
endef

# Register database drivers to make. For every item in this array, there should
# be three separate targets elsewhere in the Makefile. Here's an example using a
# made-up DBMS:
#
# foodb-test-setup:
# command to create $(TEST_DB_NAME)
# foodb-test-teardown:
# command to drop $(TEST_DB_NAME)
# foodb:
# go build ...
#
# One should have a target suffix "-test-teardown", another should have the
# target suffix "-test-setup" and the last one is just named after the DBMS,
# which builds the CLI binary.
DRIVERS ?= postgres mysql
test:
$(GO) test $(ARGS) . ./internal/...

SETUPS=$(addsuffix -test-setup, $(DRIVERS))
TEARDOWNS=$(addsuffix -test-teardown, $(DRIVERS))

test: test-teardowns test-setups
go test $(ARGS) . ./internal/stub $(addprefix ./drivers/, $(DRIVERS))
test-setups: $(SETUPS)
test-teardowns: $(TEARDOWNS)

.PHONY: $(DRIVERS) clean
clean:
rm $(BIN)

postgres:
go build -o $(BIN) -v \
$(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/version.Driver=postgres" \
./drivers/postgres/godfish
postgres-test:
$(GO) test $(ARGS) ./drivers/postgres
postgres-test-teardown:
dropdb --if-exists $(TEST_DB_NAME)
postgres-test-setup:
createdb -E utf8 $(TEST_DB_NAME)

mysql:
go build -o $(BIN) -v \
$(GO) build -o $(BIN) -v \
-ldflags "$(LDFLAGS) \
-X $(PKG_IMPORT_PATH)/internal/version.Driver=mysql" \
./drivers/mysql/godfish
mysql-test:
$(GO) test $(ARGS) ./drivers/mysql
mysql-test-teardown:
mysql -u $(DB_USER) -h $(DB_HOST) \
-e "DROP DATABASE IF EXISTS ${TEST_DB_NAME}"
Expand Down

0 comments on commit 6ba4d3e

Please sign in to comment.