diff options
| author | Richard Hansen <rhansen@rhansen.org> | 2016-01-23 03:45:02 -0500 |
|---|---|---|
| committer | Richard Hansen <rhansen@rhansen.org> | 2016-01-31 16:13:58 -0500 |
| commit | 5dcceb88a124f2ba8a6c4475bd2c87d629f54950 (patch) | |
| tree | 5ff8d408b22cb777ede7c106708f3f03e7239a60 /tools | |
| parent | 57f1ad53e202861f2f7c858f970782a2351dcb76 (diff) | |
| download | gitlab-5dcceb88a124f2ba8a6c4475bd2c87d629f54950.tar.gz | |
improve error handling
Break up pipelines and check the exit status of non-basic commands to
ensure that any problems cause the scripts/testcases to fail right
away.
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/build_test_env.sh | 27 | ||||
| -rwxr-xr-x | tools/functional_tests.sh | 48 | ||||
| -rwxr-xr-x | tools/py_functional_tests.sh | 6 |
3 files changed, 46 insertions, 35 deletions
diff --git a/tools/build_test_env.sh b/tools/build_test_env.sh index c824107..38c31cc 100755 --- a/tools/build_test_env.sh +++ b/tools/build_test_env.sh @@ -48,7 +48,7 @@ do command -v "${req}" >/dev/null 2>&1 || fatal "${req} is required" done -VENV=$(pwd)/.venv +VENV=$(pwd)/.venv || exit 1 cleanup() { rm -f /tmp/python-gitlab.cfg @@ -62,7 +62,7 @@ cleanup() { trap 'exit 1' HUP INT TERM } -docker run --name gitlab-test --detach --publish 8080:80 \ +try docker run --name gitlab-test --detach --publish 8080:80 \ --publish 2222:22 gpocentek/test-python-gitlab:latest >/dev/null 2>&1 LOGIN='root' @@ -87,11 +87,16 @@ done sleep 5 # Get the token -TOKEN=$(curl -s http://localhost:8080/api/v3/session \ - -X POST \ - --data "login=$LOGIN&password=$PASSWORD" \ - | python -c \ - 'import sys, json; print(json.load(sys.stdin)["private_token"])') +TOKEN_JSON=$( + try curl -s http://localhost:8080/api/v3/session \ + -X POST \ + --data "login=$LOGIN&password=$PASSWORD" +) || exit 1 +TOKEN=$( + pecho "${TOKEN_JSON}" | + try python -c \ + 'import sys, json; print(json.load(sys.stdin)["private_token"])' +) || exit 1 cat > $CONFIG << EOF [global] @@ -106,9 +111,9 @@ EOF log "Config file content ($CONFIG):" log <$CONFIG -"$VENV_CMD" "$VENV" -. "$VENV"/bin/activate -pip install -rrequirements.txt -pip install -e . +try "$VENV_CMD" "$VENV" +. "$VENV"/bin/activate || fatal "failed to activate Python virtual environment" +try pip install -rrequirements.txt +try pip install -e . sleep 20 diff --git a/tools/functional_tests.sh b/tools/functional_tests.sh index 2ad0219..0282b30 100755 --- a/tools/functional_tests.sh +++ b/tools/functional_tests.sh @@ -14,67 +14,73 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -setenv_script=$(dirname "$0")/build_test_env.sh +setenv_script=$(dirname "$0")/build_test_env.sh || exit 1 BUILD_TEST_ENV_AUTO_CLEANUP=true -. "$setenv_script" "$@" - -set -e +. "$setenv_script" "$@" || exit 1 printf %s "Testing project creation... " -PROJECT_ID=$(GITLAB project create --name test-project1 \ - | grep ^id: | cut -d' ' -f2) -GITLAB project list | grep -q test-project1 +OUTPUT=$(try GITLAB project create --name test-project1) || exit 1 +PROJECT_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) +OUTPUT=$(try GITLAB project list) || exit 1 +pecho "${OUTPUT}" | grep -q test-project1 || fatal "test failed" OK printf %s "Testing project update... " -GITLAB project update --id "$PROJECT_ID" --description "My New Description" +GITLAB project update --id "$PROJECT_ID" --description "My New Description" \ + || fatal "test failed" OK printf %s "Testing user creation... " -USER_ID=$(GITLAB user create --email fake@email.com --username user1 \ - --name "User One" --password fakepassword | grep ^id: | cut -d' ' -f2) +OUTPUT=$(GITLAB user create --email fake@email.com --username user1 \ + --name "User One" --password fakepassword) || fatal "test failed" OK +USER_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) printf %s "Testing verbose output... " -GITLAB -v user list | grep -q avatar-url +OUTPUT=$(try GITLAB -v user list) || exit 1 +pecho "${OUTPUT}" | grep -q avatar-url || fatal "test failed" OK printf %s "Testing CLI args not in output... " -GITLAB -v user list | grep -qv config-file +OUTPUT=$(try GITLAB -v user list) || exit 1 +pecho "${OUTPUT}" | grep -qv config-file || fatal "test failed" OK printf %s "Testing adding member to a project... " GITLAB project-member create --project-id "$PROJECT_ID" \ - --user-id "$USER_ID" --access-level 40 >/dev/null 2>&1 + --user-id "$USER_ID" --access-level 40 >/dev/null 2>&1 \ + || fatal "test failed" OK printf %s "Testing file creation... " GITLAB project-file create --project-id "$PROJECT_ID" \ --file-path README --branch-name master --content "CONTENT" \ - --commit-message "Initial commit" >/dev/null 2>&1 + --commit-message "Initial commit" >/dev/null 2>&1 || fatal "test failed" OK printf %s "Testing issue creation... " -ISSUE_ID=$(GITLAB project-issue create --project-id "$PROJECT_ID" \ - --title "my issue" --description "my issue description" \ - | grep ^id: | cut -d' ' -f2) +OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \ + --title "my issue" --description "my issue description") \ + || fatal "test failed" OK +ISSUE_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) printf %s "Testing note creation... " GITLAB project-issue-note create --project-id "$PROJECT_ID" \ - --issue-id "$ISSUE_ID" --body "the body" >/dev/null 2>&1 + --issue-id "$ISSUE_ID" --body "the body" >/dev/null 2>&1 \ + || fatal "test failed" OK printf %s "Testing branch creation... " GITLAB project-branch create --project-id "$PROJECT_ID" \ - --branch-name branch1 --ref master >/dev/null 2>&1 + --branch-name branch1 --ref master >/dev/null 2>&1 || fatal "test failed" OK printf %s "Testing branch deletion... " GITLAB project-branch delete --project-id "$PROJECT_ID" \ - --name branch1 >/dev/null 2>&1 + --name branch1 >/dev/null 2>&1 || fatal "test failed" OK printf %s "Testing project deletion... " -GITLAB project delete --id "$PROJECT_ID" +GITLAB project delete --id "$PROJECT_ID" || fatal "test failed" OK diff --git a/tools/py_functional_tests.sh b/tools/py_functional_tests.sh index 4538541..0d00c5f 100755 --- a/tools/py_functional_tests.sh +++ b/tools/py_functional_tests.sh @@ -14,8 +14,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -setenv_script=$(dirname "$0")/build_test_env.sh +setenv_script=$(dirname "$0")/build_test_env.sh || exit 1 BUILD_TEST_ENV_AUTO_CLEANUP=true -. "$setenv_script" "$@" +. "$setenv_script" "$@" || exit 1 -python "$(dirname "$0")"/python_test.py +try python "$(dirname "$0")"/python_test.py |
