Skip to content

Commit

Permalink
Merge pull request #1 from samalba/integration-tests
Browse files Browse the repository at this point in the history
Implemented integration tests
  • Loading branch information
samalba authored Dec 6, 2018
2 parents 5472a22 + c4098da commit 0db3236
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 8 deletions.
31 changes: 24 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
version: 2

workflows:
version: 2
build:
jobs:
- build

jobs:
build:
docker:
Expand All @@ -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

5 changes: 4 additions & 1 deletion builder/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
67 changes: 67 additions & 0 deletions test/integration.sh
Original file line number Diff line number Diff line change
@@ -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 <absolute path to chainkit binary>"
exit 1
}
run_tests "$1"

0 comments on commit 0db3236

Please sign in to comment.