From c4098da5ee444be1652cc56d679f7e60e773dec7 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 4 Dec 2018 18:01:34 -0800 Subject: [PATCH] Implemented integration tests Signed-off-by: Sam Alba --- .circleci/config.yml | 31 +++++++++++++++----- builder/parser.go | 5 +++- test/integration.sh | 67 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 8 deletions(-) create mode 100755 test/integration.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index ea056c8..08feb66 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,11 +1,5 @@ version: 2 -workflows: - version: 2 - build: - jobs: - - build - jobs: build: docker: @@ -26,8 +20,31 @@ jobs: - run: name: Build command: - go build + make - save_cache: key: v1-pkg-cache paths: - "/go/pkg" + - persist_to_workspace: + root: . + paths: + - chainkit + + integration-test: + machine: true + steps: + - checkout + - attach_workspace: + at: /tmp/build + - run: ./test/integration.sh /tmp/build/chainkit + + +workflows: + version: 2 + build: + jobs: + - build + - integration-test: + requires: + - build + diff --git a/builder/parser.go b/builder/parser.go index bd773fd..f77b903 100644 --- a/builder/parser.go +++ b/builder/parser.go @@ -28,7 +28,10 @@ func (p *Parser) Parse(r io.Reader, opts BuildOpts) error { p.processLine(text, opts) } - return scanner.Err() + //FIXME: on Linux, the scanner returns an error on success: + // -> read |0: file already closed + //return scanner.Err() + return nil } func (p *Parser) processLine(text string, opts BuildOpts) { diff --git a/test/integration.sh b/test/integration.sh new file mode 100755 index 0000000..6828c00 --- /dev/null +++ b/test/integration.sh @@ -0,0 +1,67 @@ +#!/bin/sh + +TMP_DIR=/tmp/chainkit-integration-tests +PROJECT_NAME=foo +CMD="" + +test_create() { + $CMD create $PROJECT_NAME + ( + # Check that key files have been created + cd $PROJECT_NAME + [ -f chainkit.yml ] + [ -f Dockerfile ] + [ -f app.go ] + [ -d cmd ] + ) + # Check that creating the same project fails + $CMD create $PROJECT_NAME || true +} + +test_build() { + # Check that you cannot build outside the project dir + $CMD build || true + ( + # Test a build that works + cd $PROJECT_NAME + $CMD build + ) +} + +test_start() { + $CMD start --cwd $PROJECT_NAME > chainkit-start.log 2>&1 & + # Give some time for the chain to start + sleep 3 + tail chainkit-start.log + curl -I -X GET --fail http://localhost:42001 +} + +cleanup() { + docker rm -f chainkit-$PROJECT_NAME + docker rmi chainkit-$PROJECT_NAME +} + +run_tests() { + CMD="$1" + # clear-up tmp-dir if exists + rm -rf $TMP_DIR + mkdir -p ${TMP_DIR}/src + ( + cd ${TMP_DIR}/src + export GOPATH=$TMP_DIR + set -e + set -x + test_create + test_build + test_start + set +x + set +e + cleanup + ) +} + +[ -z "$1" ] && { + echo "Usage: $0 " + exit 1 +} +run_tests "$1"