diff --git a/.circleci/config.yml b/.circleci/config.yml index bab1dd08ef..c3351e40e5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -31,20 +31,23 @@ jobs: - image: redis:6 steps: - checkout - - run: - name: install dockerize - command: wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && sudo tar -C /usr/local/bin -xzvf dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz && rm dockerize-linux-amd64-$DOCKERIZE_VERSION.tar.gz - environment: - DOCKERIZE_VERSION: v0.3.0 - - run: - name: Wait for redis - command: dockerize -wait tcp://localhost:6379 -timeout 1m - - run: - name: go_test with race - command: go test -tags race --race --timeout 60s -v ./... - - run: - name: go_test - command: go test -tags all --timeout 60s -v ./... + - restore_cache: + keys: + - v1-dockerize-{{ checksum "Makefile" }} + - v1-dockerize- + - run: make dockerize + - save_cache: + key: v1-dockerize-{{ checksum "Makefile" }} + paths: + - dockerize.tar.gz + - restore_cache: + keys: + - v3-go-mod-{{ checksum "go.sum" }} + - run: make test + - save_cache: + key: v3-go-mod-{{ checksum "go.sum" }} + paths: + - /home/circleci/go/pkg/mod build_binaries: docker: diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..032c4a401a --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +MAKEFLAGS += --warn-undefined-variables +MAKEFLAGS += --no-builtin-rules +MAKEFLAGS += --no-builtin-variables + +.PHONY: test +#: run all tests +test: test_with_race test_all + +.PHONY: test_with_race +#: run only tests tagged with potential race conditions +test_with_race: wait_for_redis + @echo + @echo "+++ testing - race conditions?" + @echo + go test -tags race --race --timeout 60s -v ./... + +.PHONY: test_all +#: run all tests, but with no race condition detection +test_all: wait_for_redis + @echo + @echo "+++ testing - all the tests" + @echo + go test -tags all --timeout 60s -v ./... + +.PHONY: wait_for_redis +# wait for Redis to become available for test suite +wait_for_redis: dockerize + @echo + @echo "+++ We need a Redis running to run the tests." + @echo + @echo "Checking with dockerize $(shell ./dockerize --version)" + @./dockerize -wait tcp://localhost:6379 -timeout 30s + +# ensure the dockerize command is available +dockerize: dockerize.tar.gz + tar xzvmf dockerize.tar.gz + +HOST_OS := $(shell uname -s | tr A-Z a-z) +# You can override this version from an environment variable. +DOCKERIZE_VERSION ?= v0.6.1 +DOCKERIZE_RELEASE_ASSET := dockerize-${HOST_OS}-amd64-${DOCKERIZE_VERSION}.tar.gz + +dockerize.tar.gz: + @echo + @echo "+++ Retrieving dockerize tool for Redis readiness check." + @echo + curl --location --silent --show-error \ + --output dockerize.tar.gz \ + https://github.com/jwilder/dockerize/releases/download/${DOCKERIZE_VERSION}/${DOCKERIZE_RELEASE_ASSET} \ + && file dockerize.tar.gz | grep --silent gzip + +.PHONY: clean +clean: + rm -f dockerize.tar.gz + rm -f dockerize