Skip to content

Commit

Permalink
Add convenient make target "acceptance" for tests
Browse files Browse the repository at this point in the history
This automatically starts docker and everything and tests it.
  • Loading branch information
petoju committed Feb 25, 2021
1 parent 7c2c815 commit 4ee9f49
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 52 deletions.
13 changes: 13 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=mysql
TERRAFORM_VERSION=0.14.7
TEST_PASSWORD=my-secret-pw

default: build

Expand All @@ -22,6 +23,18 @@ bin/terraform:
testacc: fmtcheck bin/terraform
PATH="$(CURDIR)/bin:${PATH}" TF_ACC=1 go test $(TEST) -v $(TESTARGS) -timeout=30s

acceptance: testversion5.6 testversion5.7 testversion8.0

testversion%:
$(MAKE) MYSQL_VERSION=$* MYSQL_PORT=33$(shell echo "$*" | tr -d '.') testversion

testversion:
-docker run --rm --name test-mysql$(MYSQL_VERSION) -e MYSQL_ROOT_PASSWORD="$(TEST_PASSWORD)" -d -p $(MYSQL_PORT):3306 mysql:$(MYSQL_VERSION)
@while ! mysql -h 127.0.0.1 -P $(MYSQL_PORT) -p"$(TEST_PASSWORD)" -u root -e 'SELECT 1'; do echo 'Waiting for MySQL...'; sleep 1; done
-mysql -h 127.0.0.1 -u root -P $(MYSQL_PORT) -p"$(TEST_PASSWORD)" -e "INSTALL PLUGIN mysql_no_login SONAME 'mysql_no_login.so';"
MYSQL_PASSWORD="$(TEST_PASSWORD)" MYSQL_ENDPOINT=127.0.0.1:$(MYSQL_PORT) $(MAKE) testacc
docker rm -f test-mysql$(MYSQL_VERSION)

vet:
@echo "go vet ."
@go vet $$(go list ./... | grep -v vendor/) ; if [ $$? -eq 1 ]; then \
Expand Down
11 changes: 3 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ $ make testacc
If you want to run the Acceptance tests on your own machine with a MySQL in Docker:

```bash
$ docker run --rm --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -d -p 3306:3306 mysql:5.7
$ # wait for a few seconds to let MySQL stand up, check the logs with: docker logs -f some-mysql
$ export MYSQL_USERNAME=root
$ export MYSQL_ENDPOINT=localhost:3306
$ export MYSQL_PASSWORD=my-secret-pw
$ mysql -h 127.0.0.1 -u root -p"${MYSQL_PASSWORD}" -e "INSTALL PLUGIN mysql_no_login SONAME 'mysql_no_login.so';"
$ make testacc
$ docker rm -f some-mysql
make acceptance
# or to test only one mysql version:
make testversion8.0
```
Loading

0 comments on commit 4ee9f49

Please sign in to comment.