Skip to content

Commit

Permalink
Add a way to run tests locally (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomMoulard authored Jan 11, 2022
1 parent b35a788 commit 6336983
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 78 deletions.
34 changes: 13 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
- name: Check out code
uses: actions/checkout@v2

- name: Install Test tools
run: sudo apt-get install ca-certificates

- name: Cache Go modules
uses: actions/cache@v2
with:
Expand All @@ -42,24 +39,19 @@ jobs:
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}

- name: Install golangci-lint
run: golangci-lint run

- name: Install stores
run: |
script/install_consul.sh 1.1.0
script/install_dynamodb_local.sh
script/install_etcd.sh 3.3.8
script/install_zk.sh 3.4.14
script/install_redis.sh 4.0.10
- name: Install Compose
uses: ndeloof/[email protected]
with:
legacy: true

- name: Run stores
run: |
./consul agent -server -bootstrap -advertise=127.0.0.1 -data-dir /tmp/consul -config-file=./config.json 1>/dev/null &
./etcd/etcd --listen-client-urls 'http://0.0.0.0:4001' --advertise-client-urls 'http://127.0.0.1:4001' >/dev/null 2>&1 &
./zk/bin/zkServer.sh start ./zk/conf/zoo.cfg 1> /dev/null
./redis/src/redis-server &
java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -inMemory &
- name: Install golangci-lint
run: make validate

- name: Run tests
run: go test -v -race ./...
run: make test
env:
TEST_ARGS: "--count=1" # disable go test cache

- name: Display docker-compose logs
if: failure()
run: docker-compose -f script/docker-compose.yml logs
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.PHONY: all
all: validate test clean

## Run validates
.PHONY: validate
validate:
golangci-lint run

PACKAGES=$(shell go list ./store/...)

## Run tests
.PHONY: test
test: test-start-stack
test: ${PACKAGES}

## Run tests for ${PACKAGES}
## Example: make github.com/kvtools/valkeyrie/store/redis
.PHONY: ${PACKAGES}
${PACKAGES}:
go test -v -race ${TEST_ARGS} $@

## Launch docker stack for test
.PHONY: test-start-stack
test-start-stack:
docker-compose -f script/docker-compose.yml up --wait

## Clean local data
.PHONY: clean
clean:
docker-compose -f script/docker-compose.yml down
$(RM) goverage.report $(shell find . -type f -name *.out)
53 changes: 53 additions & 0 deletions script/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3.9"

# when running test local, you can specify the image version using the
# <service>_VERSION.
# Example, to run consul with the version 1.8:
# CONSUL_VERSION=1.8 make

services:
consul:
image: consul:${CONSUL_VERSION:-1.1.0}
container_name: consul
command: agent -server -bootstrap -client 0.0.0.0
environment:
CONSUL_LOCAL_CONFIG: '{"session_ttl_min": "1s"}'
healthcheck:
test: consul info | awk '/health_score/{if ($$3 >=1) exit 1; else exit 0}'
ports:
- 8500:8500

etcd:
image: quay.io/coreos/etcd:${ETCD_VERSION:-v3.3.8}
container_name: etcd
command: etcd --listen-client-urls 'http://0.0.0.0:4001' --advertise-client-urls 'http://127.0.0.1:4001'
healthcheck:
test: etcdctl --endpoints http://127.0.0.1:4001 cluster-health
ports:
- 4001:4001
volumes:
- /usr/share/ca-certificates/:/etc/ssl/certs

zookeeper:
image: zookeeper:${ZK_VERSION:-3.4.14}
container_name: zookeeper
healthcheck:
test: nc -z localhost 2181 || exit 1
ports:
- 2181:2181

redis:
image: redis:${REDIS_VERSION:-4.0.10}
container_name: redis
healthcheck:
test: redis-cli ping
ports:
- 6379:6379

dynamodb:
image: amazon/dynamodb-local:${DYNAMODB_VERSION:-1.18.0}
container_name: dynamodb
healthcheck:
test: curl localhost:8000
ports:
- 8000:8000
18 changes: 0 additions & 18 deletions script/install_consul.sh

This file was deleted.

4 changes: 0 additions & 4 deletions script/install_dynamodb_local.sh

This file was deleted.

11 changes: 0 additions & 11 deletions script/install_etcd.sh

This file was deleted.

12 changes: 0 additions & 12 deletions script/install_redis.sh

This file was deleted.

12 changes: 0 additions & 12 deletions script/install_zk.sh

This file was deleted.

0 comments on commit 6336983

Please sign in to comment.