Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[dev/ci] test in dev and CI the same way #333

Merged
merged 4 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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