|
1 | | -#!/bin/bash |
| 1 | +#!/bin/sh |
2 | 2 | # Copyright (C) 2015 Gauvain Pocentek <gauvain@pocentek.net> |
3 | 3 | # |
4 | 4 | # This program is free software: you can redistribute it and/or modify |
|
14 | 14 | # You should have received a copy of the GNU Lesser General Public License |
15 | 15 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | | -cleanup() { |
18 | | - rm -f /tmp/python-gitlab.cfg |
19 | | - docker kill gitlab-test >/dev/null 2>&1 |
20 | | - docker rm gitlab-test >/dev/null 2>&1 |
21 | | - deactivate || true |
22 | | - rm -rf $VENV |
23 | | -} |
24 | | -trap cleanup EXIT |
25 | | - |
26 | | -setenv_script=$(dirname $0)/build_test_env.sh |
27 | | - |
28 | | -. $setenv_script "$@" |
29 | | - |
30 | | -CONFIG=/tmp/python-gitlab.cfg |
31 | | -GITLAB="gitlab --config-file $CONFIG" |
32 | | -GREEN='\033[0;32m' |
33 | | -NC='\033[0m' |
34 | | -OK="echo -e ${GREEN}OK${NC}" |
35 | | - |
36 | | -VENV=$(pwd)/.venv |
37 | | - |
38 | | -$VENV_CMD $VENV |
39 | | -. $VENV/bin/activate |
40 | | -pip install -rrequirements.txt |
41 | | -pip install -e . |
42 | | - |
43 | | -# NOTE(gpocentek): the first call might fail without a little delay |
44 | | -sleep 20 |
45 | | - |
46 | | -set -e |
47 | | - |
48 | | -echo -n "Testing project creation... " |
49 | | -PROJECT_ID=$($GITLAB project create --name test-project1 | grep ^id: | cut -d' ' -f2) |
50 | | -$GITLAB project list | grep -q test-project1 |
51 | | -$OK |
52 | | - |
53 | | -echo -n "Testing project update... " |
54 | | -$GITLAB project update --id $PROJECT_ID --description "My New Description" |
55 | | -$OK |
56 | | - |
57 | | -echo -n "Testing user creation... " |
58 | | -USER_ID=$($GITLAB user create --email fake@email.com --username user1 --name "User One" --password fakepassword | grep ^id: | cut -d' ' -f2) |
59 | | -$OK |
60 | | - |
61 | | -echo -n "Testing verbose output... " |
62 | | -$GITLAB -v user list | grep -q avatar-url |
63 | | -$OK |
64 | | - |
65 | | -echo -n "Testing CLI args not in output... " |
66 | | -$GITLAB -v user list | grep -qv config-file |
67 | | -$OK |
68 | | - |
69 | | -echo -n "Testing adding member to a project... " |
70 | | -$GITLAB project-member create --project-id $PROJECT_ID --user-id $USER_ID --access-level 40 >/dev/null 2>&1 |
71 | | -$OK |
72 | | - |
73 | | -echo -n "Testing file creation... " |
74 | | -$GITLAB project-file create --project-id $PROJECT_ID --file-path README --branch-name master --content "CONTENT" --commit-message "Initial commit" >/dev/null 2>&1 |
75 | | -$OK |
76 | | - |
77 | | -echo -n "Testing issue creation... " |
78 | | -ISSUE_ID=$($GITLAB project-issue create --project-id $PROJECT_ID --title "my issue" --description "my issue description" | grep ^id: | cut -d' ' -f2) |
79 | | -$OK |
80 | | - |
81 | | -echo -n "Testing note creation... " |
82 | | -$GITLAB project-issue-note create --project-id $PROJECT_ID --issue-id $ISSUE_ID --body "the body" >/dev/null 2>&1 |
83 | | -$OK |
84 | | - |
85 | | -echo -n "Testing branch creation... " |
86 | | -$GITLAB project-branch create --project-id $PROJECT_ID --branch-name branch1 --ref master >/dev/null 2>&1 |
87 | | -$OK |
88 | | - |
89 | | -echo -n "Testing branch deletion... " |
90 | | -$GITLAB project-branch delete --project-id $PROJECT_ID --name branch1 >/dev/null 2>&1 |
91 | | -$OK |
92 | | - |
93 | | -echo -n "Testing project deletion... " |
94 | | -$GITLAB project delete --id $PROJECT_ID |
95 | | -$OK |
| 17 | +setenv_script=$(dirname "$0")/build_test_env.sh || exit 1 |
| 18 | +BUILD_TEST_ENV_AUTO_CLEANUP=true |
| 19 | +. "$setenv_script" "$@" || exit 1 |
| 20 | + |
| 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 | +' |
| 27 | + |
| 28 | +testcase "project update" ' |
| 29 | + GITLAB project update --id "$PROJECT_ID" --description "My New Description" |
| 30 | +' |
| 31 | + |
| 32 | +testcase "user creation" ' |
| 33 | + OUTPUT=$(GITLAB user create --email fake@email.com --username user1 \ |
| 34 | + --name "User One" --password fakepassword) |
| 35 | +' |
| 36 | +USER_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) |
| 37 | + |
| 38 | +testcase "verbose output" ' |
| 39 | + OUTPUT=$(try GITLAB -v user list) || exit 1 |
| 40 | + pecho "${OUTPUT}" | grep -q avatar-url |
| 41 | +' |
| 42 | + |
| 43 | +testcase "CLI args not in output" ' |
| 44 | + OUTPUT=$(try GITLAB -v user list) || exit 1 |
| 45 | + pecho "${OUTPUT}" | grep -qv config-file |
| 46 | +' |
| 47 | + |
| 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 | +' |
| 52 | + |
| 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 | +' |
| 58 | + |
| 59 | +testcase "issue creation" ' |
| 60 | + OUTPUT=$(GITLAB project-issue create --project-id "$PROJECT_ID" \ |
| 61 | + --title "my issue" --description "my issue description") |
| 62 | +' |
| 63 | +ISSUE_ID=$(pecho "${OUTPUT}" | grep ^id: | cut -d' ' -f2) |
| 64 | + |
| 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 | +' |
| 69 | + |
| 70 | +testcase "branch creation" ' |
| 71 | + GITLAB project-branch create --project-id "$PROJECT_ID" \ |
| 72 | + --branch-name branch1 --ref master >/dev/null 2>&1 |
| 73 | +' |
| 74 | + |
| 75 | +testcase "branch deletion" ' |
| 76 | + GITLAB project-branch delete --project-id "$PROJECT_ID" \ |
| 77 | + --name branch1 >/dev/null 2>&1 |
| 78 | +' |
| 79 | + |
| 80 | +testcase "project deletion" ' |
| 81 | + GITLAB project delete --id "$PROJECT_ID" |
| 82 | +' |
0 commit comments