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

Prepare setup for running e2e tests #1435

Merged
merged 10 commits into from
Oct 28, 2019
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
64 changes: 47 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ version: 2
run_on_machine: &run_on_machine
machine:
docker_layer_caching: false
image: ubuntu-1604:201903-01

run_on_docker: &run_on_docker
docker:
- image: circleci/golang:1.13.0

restore_go_mod_cache: &restore_go_mod_cache
go_path: &go_path /tmp/go/path

restore_go_path: &restore_go_path
- restore_cache:
keys:
- go-mod-cache-{{ checksum "go.sum" }}
- go-path-{{ checksum "go.sum" }}

save_go_mod_cache: &save_go_mod_cache
save_go_path: &save_go_path
- save_cache:
key: go-mod-cache-{{ checksum "go.sum" }}
key: go-path-{{ checksum "go.sum" }}
paths:
- /go/pkg/mod
- *go_path

go_cache_dir: &go_cache_dir /tmp/go/cache

Expand All @@ -38,26 +41,44 @@ jobs:
"test":
<<: *run_on_docker
environment:
- GOPATH : *go_path
- GOCACHE: *go_cache_dir
steps:
- checkout
- setup_remote_docker
- run: docker swarm init
- <<: *restore_go_cache
- <<: *restore_go_mod_cache
- <<: *restore_go_path
- run: make test
- <<: *save_go_mod_cache
- <<: *save_go_path
- <<: *save_go_cache
- run: bash <(curl -s https://codecov.io/bash)

"test_e2e":
<<: *run_on_machine
environment:
- GOPATH : *go_path
- GOCACHE: *go_cache_dir
steps:
- checkout
- run:
name: "Install Go"
command: |
sudo rm -rf /usr/local/go
curl -sSL "https://dl.google.com/go/go1.13.linux-amd64.tar.gz" | sudo tar -xz -C /usr/local/
echo "export PATH=$PATH:/usr/local/go/bin" >> $BASH_ENV
- run: docker swarm init
- <<: *restore_go_cache
- <<: *restore_go_path
- run: make e2e
- <<: *save_go_path
- <<: *save_go_cache

"lint":
docker:
- image: golangci/golangci-lint:v1.18
environment:
- GOCACHE: *go_cache_dir
steps:
- checkout
- <<: *restore_go_mod_cache
- run: make lint

"publish_docker_dev":
Expand Down Expand Up @@ -95,6 +116,10 @@ workflows:
ignore:
- "dev"
- "master"
- "test_e2e":
requires:
- "test"
- "lint"

release_dev:
jobs:
Expand All @@ -110,10 +135,13 @@ workflows:
ignore: /.*/
branches:
only: dev
- "publish_docker_dev":
- "test_e2e":
requires:
- "test"
- "lint"
- "publish_docker_dev":
requires:
- "test_e2e"

test_prod:
jobs:
Expand All @@ -129,6 +157,10 @@ workflows:
ignore: /.*/
branches:
only: master
- "test_e2e":
requires:
- "test"
- "lint"

release_prod:
jobs:
Expand All @@ -144,12 +176,10 @@ workflows:
only: /^v.*/
branches:
ignore: /.*/
- "publish_docker_prod":
- "test_e2e":
requires:
- "test"
- "lint"
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
- "publish_docker_prod":
requires:
- "test_e2e"
29 changes: 24 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
.PHONY: all check-version docker-publish docker-publish-dev docker-tools dev lint dep build test mock protobuf changelog clean genesis
.PHONY: all e2e check-version docker-publish docker-publish-dev docker-tools dev dev-stop dev-start lint dep build test mock protobuf changelog clean genesis clean-build clean-docker clean-e2e

MAJOR_VERSION := $(shell echo $(version) | cut -d . -f 1)
MINOR_VERSION := $(shell echo $(version) | cut -d . -f 1-2)
PATCH_VERSION := $(version)

all: clean lint test build
all: clean lint build test e2e

check-version:
ifndef version
Expand Down Expand Up @@ -39,14 +39,26 @@ docker-tools:
dev: docker-dev
- ./scripts/dev.sh

dev-start: docker-dev
./scripts/dev.sh -q

dev-stop: docker-dev
./scripts/dev.sh stop

dep:
go mod download

build: check-version dep
go build -mod=readonly -o ./bin/engine -ldflags="-X 'github.com/mesg-foundation/engine/version.Version=$(version)'" core/main.go

e2e: export MESG_PATH = $(PWD)/e2e.test/mesg
e2e: clean-e2e
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
@$(MAKE) dev-start
- go test -mod=readonly -v ./e2e/...
@$(MAKE) dev-stop

test: dep
go test -mod=readonly -v -coverprofile=coverage.txt ./...
go test -short -mod=readonly -v -coverprofile=coverage.txt ./...

lint:
golangci-lint run
Expand All @@ -60,12 +72,19 @@ protobuf: docker-tools
changelog:
./scripts/changelog.sh $(milestone)

clean:
clean-e2e:
- rm -rf $(PWD)/e2e.test/mesg

clean-build:
- rm -rf bin/*

clean-docker:
- docker image rm \
mesg/engine:$(version) \
mesg/engine:latest \
mesg/engine:dev 2>/dev/null

clean: clean-e2e clean-build clean-docker

genesis:
go run internal/tools/gen-genesis/main.go --path $(path) --chain-id $(chain-id) --validators $(validators)
go run internal/tools/gen-genesis/main.go --path $(path) --chain-id $(chain-id) --validators $(validators)
11 changes: 11 additions & 0 deletions e2e/api_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"testing"
)

func TestAPI(t *testing.T) {
if testing.Short() {
t.Skip()
}
}
93 changes: 64 additions & 29 deletions scripts/dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ set -e
MESG_NAME=${MESG_NAME:-"engine"}
MESG_PATH=${MESG_PATH:-"$HOME/.mesg"}

MESG_TENDERMINT_NETWORK="mesg-tendermint"
MESG_SERVER_PORT=${MESG_SERVER_PORT:-"50052"}
MESG_TENDERMINT_NETWORK="mesg-tendermint"
MESG_TENDERMINT_PORT=${MESG_TENDERMINT_PORT:-"26656"}

function onexit {
Expand Down Expand Up @@ -37,31 +37,66 @@ function docker_network_remove {
docker network remove "$1"
}

trap onexit EXIT

if ! docker_network_exist "$MESG_NAME"; then
docker_network_create "$MESG_NAME"
fi

if ! docker_network_exist "$MESG_TENDERMINT_NETWORK"; then
docker_network_create "$MESG_TENDERMINT_NETWORK"
fi

mkdir -p $MESG_PATH

echo "create docker service: "
docker service create \
--name $MESG_NAME \
--tty \
--label com.docker.stack.namespace=$MESG_NAME \
--label com.docker.stack.image=mesg/engine:local \
--env MESG_NAME=$MESG_NAME \
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock \
--mount type=bind,source=$MESG_PATH,destination=/root/.mesg \
--network $MESG_NAME \
--network name=$MESG_TENDERMINT_NETWORK \
--publish $MESG_SERVER_PORT:50052 \
--publish $MESG_TENDERMINT_PORT:26656 \
mesg/engine:local

docker service logs --follow --raw $MESG_NAME
function start_engine {
if ! docker_network_exist "$MESG_NAME"; then
docker_network_create "$MESG_NAME"
fi

if ! docker_network_exist "$MESG_TENDERMINT_NETWORK"; then
docker_network_create "$MESG_TENDERMINT_NETWORK"
fi

mkdir -p $MESG_PATH

echo "create docker service: "
docker service create \
--name $MESG_NAME \
--tty \
--label com.docker.stack.namespace=$MESG_NAME \
--label com.docker.stack.image=mesg/engine:local \
--env MESG_NAME=$MESG_NAME \
--mount type=bind,source=/var/run/docker.sock,destination=/var/run/docker.sock \
--mount type=bind,source=$MESG_PATH,destination=/root/.mesg \
--network $MESG_NAME \
--network name=$MESG_TENDERMINT_NETWORK \
--publish $MESG_SERVER_PORT:50052 \
--publish $MESG_TENDERMINT_PORT:26656 \
mesg/engine:local
}

function stop_engine {
onexit
}

quiet=false

while getopts "q" o; do
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
case $o in
q)
quiet=true
;;
*)
echo "unknown flag $0"
exit 1
;;
esac
done
shift $((OPTIND-1))
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved

cmd=${1:-"start"}

case $cmd in
start)
start_engine
if ! $quiet; then
trap onexit EXIT
docker service logs --follow --raw $MESG_NAME
fi
;;
stop)
stop_engine
;;
*)
echo "unknown command $cmd"
exit 1
esac