-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from samalba/integration-tests
Implemented integration tests
- Loading branch information
Showing
3 changed files
with
95 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |