Skip to content

Commit

Permalink
define a testcase() function; use it for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rhansen committed Jan 31, 2016
1 parent 033881e commit 37f6d42
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 53 deletions.
7 changes: 7 additions & 0 deletions tools/build_test_env.sh
Expand Up @@ -74,6 +74,13 @@ GITLAB() { gitlab --config-file "$CONFIG" "$@"; }
GREEN='\033[0;32m'
NC='\033[0m'
OK() { printf "${GREEN}OK${NC}\\n"; }
testcase() {
testname=$1; shift
testscript=$1; shift
printf %s "Testing ${testname}... "
eval "${testscript}" || fatal "test failed"
OK
}

log "Waiting for gitlab to come online... "
I=0
Expand Down
102 changes: 49 additions & 53 deletions tools/functional_tests.sh
Expand Up @@ -18,69 +18,65 @@ setenv_script=$(dirname "$0")/build_test_env.sh || exit 1
BUILD_TEST_ENV_AUTO_CLEANUP=true
. "$setenv_script" "$@" || exit 1

printf %s "Testing project creation... "
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
testcase "project creation" '
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
'

printf %s "Testing project update... "
GITLAB project update --id "$PROJECT_ID" --description "My New Description" \
|| fatal "test failed"
OK
testcase "project update" '
GITLAB project update --id "$PROJECT_ID" --description "My New Description"
'

printf %s "Testing user creation... "
OUTPUT=$(GITLAB user create --email fake@email.com --username user1 \
--name "User One" --password fakepassword) || fatal "test failed"
OK
testcase "user creation" '
OUTPUT=$(GITLAB user create --email fake@email.com --username user1 \
--name "User One" --password fakepassword)
'
USER_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2)

printf %s "Testing verbose output... "
OUTPUT=$(try GITLAB -v user list) || exit 1
pecho "${OUTPUT}" | grep -q avatar-url || fatal "test failed"
OK
testcase "verbose output" '
OUTPUT=$(try GITLAB -v user list) || exit 1
pecho "${OUTPUT}" | grep -q avatar-url
'

printf %s "Testing CLI args not in output... "
OUTPUT=$(try GITLAB -v user list) || exit 1
pecho "${OUTPUT}" | grep -qv config-file || fatal "test failed"
OK
testcase "CLI args not in output" '
OUTPUT=$(try GITLAB -v user list) || exit 1
pecho "${OUTPUT}" | grep -qv config-file
'

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 \
|| fatal "test failed"
OK
testcase "adding member to a project" '
GITLAB project-member create --project-id "$PROJECT_ID" \
--user-id "$USER_ID" --access-level 40 >/dev/null 2>&1
'

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 || fatal "test failed"
OK
testcase "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
'

printf %s "Testing issue creation... "
OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \
--title "my issue" --description "my issue description") \
|| fatal "test failed"
OK
testcase "issue creation" '
OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \
--title "my issue" --description "my issue description")
'
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 \
|| fatal "test failed"
OK
testcase "note creation" '
GITLAB project-issue-note create --project-id "$PROJECT_ID" \
--issue-id "$ISSUE_ID" --body "the body" >/dev/null 2>&1
'

printf %s "Testing branch creation... "
GITLAB project-branch create --project-id "$PROJECT_ID" \
--branch-name branch1 --ref master >/dev/null 2>&1 || fatal "test failed"
OK
testcase "branch creation" '
GITLAB project-branch create --project-id "$PROJECT_ID" \
--branch-name branch1 --ref master >/dev/null 2>&1
'

printf %s "Testing branch deletion... "
GITLAB project-branch delete --project-id "$PROJECT_ID" \
--name branch1 >/dev/null 2>&1 || fatal "test failed"
OK
testcase "branch deletion" '
GITLAB project-branch delete --project-id "$PROJECT_ID" \
--name branch1 >/dev/null 2>&1
'

printf %s "Testing project deletion... "
GITLAB project delete --id "$PROJECT_ID" || fatal "test failed"
OK
testcase "project deletion" '
GITLAB project delete --id "$PROJECT_ID"
'

0 comments on commit 37f6d42

Please sign in to comment.