This repository has been archived by the owner on Dec 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgogs_acceptance_test.sh
executable file
·159 lines (136 loc) · 3.72 KB
/
gogs_acceptance_test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env bash
# -*- coding: utf8 -*-
#
# Copyright (c) 2017 unfoldingWord
# http://creativecommons.org/licenses/MIT/
# See LICENSE file for details.
#
# Contributors:
# Jesse Griffin <[email protected]>
# Temp and log location
TMPDIR=/tmp/gogs_test
LOGFILE=/tmp/gogs_acceptance_test.log
get_tmp() {
# Setup temporary environment
rm -rf "$TMPDIR"
mkdir -p "$TMPDIR"
cd "$TMPDIR"
}
help() {
echo "Runs acceptance tests against our Door43 Content Service"
echo
echo "Usage: $0 [options]"
echo
echo "Options:"
echo " -H Host to run against, default is localhost:3000"
echo " -t Token for testing API"
echo " -p Password for acceptance_test user"
echo " -h Displays this messsage"
}
while test $# -gt 0; do
case "$1" in
-H|--hostname) shift; HOST=$1;;
-t|--token) shift; TOKEN=$1;;
-p|--pass) shift; PASS=":$1";;
-h|--help) help && exit 1;;
esac
shift;
done
# Setup variable defaults in case flags were not set
: ${HOST='localhost:3000'}
: ${TOKEN=false}
: ${PASS=""}
echo -n "Testing $HOST"
# Put all output into log
exec >$LOGFILE 2>&1
# Show commands being executed and exit upon any error
set -xe
# Test for Google Analytics ID
wget -q -O - https://$HOST \
| grep -q "UA-6010"
# API Tests
# Try deleting repo in case last run failed
curl -X DELETE -H "Authorization: token $TOKEN" \
https://$HOST/api/v1/repos/acceptance_test/api_test
# Create a repo
wget -q -O - \
--header="Authorization: token $TOKEN" \
--post-data="name=api_test" \
https://$HOST/api/v1/user/repos \
| grep -q "acceptance_test/api_test"
# Get list of repos for user
wget -q -O - \
--header="Authorization: token $TOKEN" \
https://$HOST/api/v1/user/repos \
| grep -q "username"
# Get repo we just created
wget -q -O - \
--header="Authorization: token $TOKEN" \
https://$HOST/api/v1/repos/acceptance_test/api_test \
| grep -q "watchers_count"
# Get list of all repos
wget -q -O - \
https://$HOST/api/v1/repos/search \
| grep -q "watchers_count"
# Delete repo we created
curl -X DELETE -H "Authorization: token $TOKEN" \
https://$HOST/api/v1/repos/acceptance_test/api_test
# Test searching without logging in
curl -X GET \
"https://$HOST/api/v1/users/search?q=acceptance_test" \
| grep -q "4959"
# Test download of code from repo
## zip ball
### master
get_tmp
wget -q https://$HOST/acceptance_test/test/archive/master.zip
unzip master.zip
[ -f test/README.md ]
### release
get_tmp
wget -q https://$HOST/acceptance_test/test/archive/v1.zip
unzip v1.zip
[ -f test/README.md ]
# tar ball
## master
get_tmp
wget -q https://$HOST/acceptance_test/test/archive/master.tar.gz
tar -xvzf master.tar.gz
[ -f test/README.md ]
### release
get_tmp
wget -q https://$HOST/acceptance_test/test/archive/v1.tar.gz
tar -xvzf v1.tar.gz
[ -f test/README.md ]
# Test repo clone-add-commit-push
# HTTPS
DATEFILE=`date +%Y-%m-%d-%H-%M-%S`
get_tmp
git clone https://acceptance_test$PASS@$HOST/acceptance_test/test.git
cd test
date > "$DATEFILE"
[ -f "$DATEFILE" ]
git add "$DATEFILE"
git commit "$DATEFILE" -m 'Adding HTTPS test file'
git push origin master
wget -q -O /dev/null https://$HOST/acceptance_test/test/raw/master/$DATEFILE
rm $DATEFILE
git commit "$DATEFILE" -m 'Removing HTTPS test file'
git push origin master
# SSH
DATEFILE=`date +%Y-%m-%d-%H-%M-%S`
get_tmp
git clone git@$HOST:acceptance_test/test.git
cd test
date > "$DATEFILE"
[ -f "$DATEFILE" ]
git add "$DATEFILE"
git commit "$DATEFILE" -m 'Adding SSH test file'
git push origin master
wget -q -O /dev/null https://$HOST/acceptance_test/test/raw/master/$DATEFILE
rm $DATEFILE
git commit "$DATEFILE" -m 'Removing SSH test file'
git push origin master
# Final cleanup
rm -rf "$TMPDIR"
echo "OK"