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

Implemented integration tests #1

Merged
merged 1 commit into from
Dec 6, 2018
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
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"