diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f18ea48..088c419 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: @@ -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/install-compose-action@v0.0.1 + 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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..748b5eb --- /dev/null +++ b/Makefile @@ -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) diff --git a/script/docker-compose.yml b/script/docker-compose.yml new file mode 100644 index 0000000..50866e7 --- /dev/null +++ b/script/docker-compose.yml @@ -0,0 +1,53 @@ +version: "3.9" + +# when running test local, you can specify the image version using the +# _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 diff --git a/script/install_consul.sh b/script/install_consul.sh deleted file mode 100755 index 7b63d6b..0000000 --- a/script/install_consul.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -if [ $# -gt 0 ] ; then - CONSUL_VERSION="$1" -else - CONSUL_VERSION="0.5.2" -fi - -# install consul -wget "https://releases.hashicorp.com/consul/${CONSUL_VERSION}/consul_${CONSUL_VERSION}_linux_amd64.zip" -unzip "consul_${CONSUL_VERSION}_linux_amd64.zip" - -# make config for minimum ttl -touch config.json -echo "{\"session_ttl_min\": \"1s\"}" >> config.json - -# check -./consul --version diff --git a/script/install_dynamodb_local.sh b/script/install_dynamodb_local.sh deleted file mode 100755 index ab1650d..0000000 --- a/script/install_dynamodb_local.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -curl -L http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz -o dynamodb_local_latest.tar.gz -tar -xzf dynamodb_local_latest.tar.gz diff --git a/script/install_etcd.sh b/script/install_etcd.sh deleted file mode 100755 index bee8567..0000000 --- a/script/install_etcd.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash - -if [ $# -gt 0 ] ; then - ETCD_VERSION="$1" -else - ETCD_VERSION="2.2.0" -fi - -curl -L https://github.com/coreos/etcd/releases/download/v$ETCD_VERSION/etcd-v$ETCD_VERSION-linux-amd64.tar.gz -o etcd-v$ETCD_VERSION-linux-amd64.tar.gz -tar xzvf etcd-v$ETCD_VERSION-linux-amd64.tar.gz -mv etcd-v$ETCD_VERSION-linux-amd64 etcd diff --git a/script/install_redis.sh b/script/install_redis.sh deleted file mode 100755 index a31288f..0000000 --- a/script/install_redis.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ $# -gt 0 ] ; then - REDIS_VERSION="$1" -else - REDIS_VERSION="3.2.6" -fi - -# install redis - -curl -L http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz -o redis.tar.gz -tar xzf redis.tar.gz && mv redis-$REDIS_VERSION redis && cd redis && make diff --git a/script/install_zk.sh b/script/install_zk.sh deleted file mode 100755 index f6383d6..0000000 --- a/script/install_zk.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ $# -gt 0 ] ; then - ZK_VERSION="$1" -else - ZK_VERSION="3.4.7" -fi - -wget "https://archive.apache.org/dist/zookeeper/zookeeper-${ZK_VERSION}/zookeeper-${ZK_VERSION}.tar.gz" -tar -xvf "zookeeper-${ZK_VERSION}.tar.gz" -mv zookeeper-${ZK_VERSION} zk -mv ./zk/conf/zoo_sample.cfg ./zk/conf/zoo.cfg