Skip to content

Commit 37f6d42

Browse files
committed
define a testcase() function; use it for tests
1 parent 033881e commit 37f6d42

File tree

2 files changed

+56
-53
lines changed

2 files changed

+56
-53
lines changed

tools/build_test_env.sh

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ GITLAB() { gitlab --config-file "$CONFIG" "$@"; }
7474
GREEN='\033[0;32m'
7575
NC='\033[0m'
7676
OK() { printf "${GREEN}OK${NC}\\n"; }
77+
testcase() {
78+
testname=$1; shift
79+
testscript=$1; shift
80+
printf %s "Testing ${testname}... "
81+
eval "${testscript}" || fatal "test failed"
82+
OK
83+
}
7784

7885
log "Waiting for gitlab to come online... "
7986
I=0

tools/functional_tests.sh

+49-53
Original file line numberDiff line numberDiff line change
@@ -18,69 +18,65 @@ setenv_script=$(dirname "$0")/build_test_env.sh || exit 1
1818
BUILD_TEST_ENV_AUTO_CLEANUP=true
1919
. "$setenv_script" "$@" || exit 1
2020

21-
printf %s "Testing project creation... "
22-
OUTPUT=$(try GITLAB project create --name test-project1) || exit 1
23-
PROJECT_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2)
24-
OUTPUT=$(try GITLAB project list) || exit 1
25-
pecho "${OUTPUT}" | grep -q test-project1 || fatal "test failed"
26-
OK
21+
testcase "project creation" '
22+
OUTPUT=$(try GITLAB project create --name test-project1) || exit 1
23+
PROJECT_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d" " -f2)
24+
OUTPUT=$(try GITLAB project list) || exit 1
25+
pecho "${OUTPUT}" | grep -q test-project1
26+
'
2727

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

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

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

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

49-
printf %s "Testing adding member to a project... "
50-
GITLAB project-member create --project-id "$PROJECT_ID" \
51-
--user-id "$USER_ID" --access-level 40 >/dev/null 2>&1 \
52-
|| fatal "test failed"
53-
OK
48+
testcase "adding member to a project" '
49+
GITLAB project-member create --project-id "$PROJECT_ID" \
50+
--user-id "$USER_ID" --access-level 40 >/dev/null 2>&1
51+
'
5452

55-
printf %s "Testing file creation... "
56-
GITLAB project-file create --project-id "$PROJECT_ID" \
57-
--file-path README --branch-name master --content "CONTENT" \
58-
--commit-message "Initial commit" >/dev/null 2>&1 || fatal "test failed"
59-
OK
53+
testcase "file creation" '
54+
GITLAB project-file create --project-id "$PROJECT_ID" \
55+
--file-path README --branch-name master --content "CONTENT" \
56+
--commit-message "Initial commit" >/dev/null 2>&1
57+
'
6058

61-
printf %s "Testing issue creation... "
62-
OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \
63-
--title "my issue" --description "my issue description") \
64-
|| fatal "test failed"
65-
OK
59+
testcase "issue creation" '
60+
OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \
61+
--title "my issue" --description "my issue description")
62+
'
6663
ISSUE_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2)
6764

68-
printf %s "Testing note creation... "
69-
GITLAB project-issue-note create --project-id "$PROJECT_ID" \
70-
--issue-id "$ISSUE_ID" --body "the body" >/dev/null 2>&1 \
71-
|| fatal "test failed"
72-
OK
65+
testcase "note creation" '
66+
GITLAB project-issue-note create --project-id "$PROJECT_ID" \
67+
--issue-id "$ISSUE_ID" --body "the body" >/dev/null 2>&1
68+
'
7369

74-
printf %s "Testing branch creation... "
75-
GITLAB project-branch create --project-id "$PROJECT_ID" \
76-
--branch-name branch1 --ref master >/dev/null 2>&1 || fatal "test failed"
77-
OK
70+
testcase "branch creation" '
71+
GITLAB project-branch create --project-id "$PROJECT_ID" \
72+
--branch-name branch1 --ref master >/dev/null 2>&1
73+
'
7874

79-
printf %s "Testing branch deletion... "
80-
GITLAB project-branch delete --project-id "$PROJECT_ID" \
81-
--name branch1 >/dev/null 2>&1 || fatal "test failed"
82-
OK
75+
testcase "branch deletion" '
76+
GITLAB project-branch delete --project-id "$PROJECT_ID" \
77+
--name branch1 >/dev/null 2>&1
78+
'
8379

84-
printf %s "Testing project deletion... "
85-
GITLAB project delete --id "$PROJECT_ID" || fatal "test failed"
86-
OK
80+
testcase "project deletion" '
81+
GITLAB project delete --id "$PROJECT_ID"
82+
'

0 commit comments

Comments
 (0)