Skip to content

Commit 6336983

Browse files
author
Tom Moulard
authored
Add a way to run tests locally (#57)
1 parent b35a788 commit 6336983

8 files changed

Lines changed: 97 additions & 78 deletions

File tree

.github/workflows/build.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ jobs:
2121
- name: Check out code
2222
uses: actions/checkout@v2
2323

24-
- name: Install Test tools
25-
run: sudo apt-get install ca-certificates
26-
2724
- name: Cache Go modules
2825
uses: actions/cache@v2
2926
with:
@@ -42,24 +39,19 @@ jobs:
4239
- name: Install golangci-lint ${{ env.GOLANGCI_LINT_VERSION }}
4340
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION}
4441

45-
- name: Install golangci-lint
46-
run: golangci-lint run
47-
48-
- name: Install stores
49-
run: |
50-
script/install_consul.sh 1.1.0
51-
script/install_dynamodb_local.sh
52-
script/install_etcd.sh 3.3.8
53-
script/install_zk.sh 3.4.14
54-
script/install_redis.sh 4.0.10
42+
- name: Install Compose
43+
uses: ndeloof/install-compose-action@v0.0.1
44+
with:
45+
legacy: true
5546

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

6450
- name: Run tests
65-
run: go test -v -race ./...
51+
run: make test
52+
env:
53+
TEST_ARGS: "--count=1" # disable go test cache
54+
55+
- name: Display docker-compose logs
56+
if: failure()
57+
run: docker-compose -f script/docker-compose.yml logs

Makefile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.PHONY: all
2+
all: validate test clean
3+
4+
## Run validates
5+
.PHONY: validate
6+
validate:
7+
golangci-lint run
8+
9+
PACKAGES=$(shell go list ./store/...)
10+
11+
## Run tests
12+
.PHONY: test
13+
test: test-start-stack
14+
test: ${PACKAGES}
15+
16+
## Run tests for ${PACKAGES}
17+
## Example: make github.com/kvtools/valkeyrie/store/redis
18+
.PHONY: ${PACKAGES}
19+
${PACKAGES}:
20+
go test -v -race ${TEST_ARGS} $@
21+
22+
## Launch docker stack for test
23+
.PHONY: test-start-stack
24+
test-start-stack:
25+
docker-compose -f script/docker-compose.yml up --wait
26+
27+
## Clean local data
28+
.PHONY: clean
29+
clean:
30+
docker-compose -f script/docker-compose.yml down
31+
$(RM) goverage.report $(shell find . -type f -name *.out)

script/docker-compose.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
version: "3.9"
2+
3+
# when running test local, you can specify the image version using the
4+
# <service>_VERSION.
5+
# Example, to run consul with the version 1.8:
6+
# CONSUL_VERSION=1.8 make
7+
8+
services:
9+
consul:
10+
image: consul:${CONSUL_VERSION:-1.1.0}
11+
container_name: consul
12+
command: agent -server -bootstrap -client 0.0.0.0
13+
environment:
14+
CONSUL_LOCAL_CONFIG: '{"session_ttl_min": "1s"}'
15+
healthcheck:
16+
test: consul info | awk '/health_score/{if ($$3 >=1) exit 1; else exit 0}'
17+
ports:
18+
- 8500:8500
19+
20+
etcd:
21+
image: quay.io/coreos/etcd:${ETCD_VERSION:-v3.3.8}
22+
container_name: etcd
23+
command: etcd --listen-client-urls 'http://0.0.0.0:4001' --advertise-client-urls 'http://127.0.0.1:4001'
24+
healthcheck:
25+
test: etcdctl --endpoints http://127.0.0.1:4001 cluster-health
26+
ports:
27+
- 4001:4001
28+
volumes:
29+
- /usr/share/ca-certificates/:/etc/ssl/certs
30+
31+
zookeeper:
32+
image: zookeeper:${ZK_VERSION:-3.4.14}
33+
container_name: zookeeper
34+
healthcheck:
35+
test: nc -z localhost 2181 || exit 1
36+
ports:
37+
- 2181:2181
38+
39+
redis:
40+
image: redis:${REDIS_VERSION:-4.0.10}
41+
container_name: redis
42+
healthcheck:
43+
test: redis-cli ping
44+
ports:
45+
- 6379:6379
46+
47+
dynamodb:
48+
image: amazon/dynamodb-local:${DYNAMODB_VERSION:-1.18.0}
49+
container_name: dynamodb
50+
healthcheck:
51+
test: curl localhost:8000
52+
ports:
53+
- 8000:8000

script/install_consul.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

script/install_dynamodb_local.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

script/install_etcd.sh

Lines changed: 0 additions & 11 deletions
This file was deleted.

script/install_redis.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

script/install_zk.sh

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)