forked from codecov/codecov-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
executable file
·404 lines (355 loc) · 15.5 KB
/
test
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
#!/bin/bash
urlencode() {
echo "$1" | curl -Gso /dev/null -w %{url_effective} --data-urlencode @- "" | cut -c 3- | sed -e 's/%0A//'
}
_SHA=$(git rev-parse HEAD)
_BRANCH=$(git rev-parse --abbrev-ref HEAD)
_BRANCH=$(urlencode $_BRANCH)
if [ "$_BRANCH" = "HEAD" ];
then
_BRANCH=""
fi
export PATH=$PWD:$PATH
function reset () {
rm -rf temp bower .bowerrc codecov.yml tests/.codecov.yml
# git commit --amend -m 'nothing special'
mkdir -p temp
mkdir -p ~/Library/Developer/Xcode/DerivedData
. tests/env
echo '{"file.txt":[null, 1, 0]}' > temp/coverage.json
echo '{"another.txt":[null, 1, 0]}' > temp/coverage.xml
touch temp/file.rb
echo 'blank' > temp/not-file.json
}
function assertDiff () {
diff <(erb "$2") <(echo "$1")
assertTrue 'Expected output differs.' $?
}
function assertContains () {
python -c "import sys; assert sys.argv[2] in sys.argv[1]" "$1" "$2" 2>/dev/null
assertTrue ">>>>>> $1 <<<<<< does not contain $2" $?
}
function assertNotContains () {
python -c "import sys; assert sys.argv[2] not in sys.argv[1]" "$1" "$2" 2>/dev/null
assertTrue ">>>>>> $1 <<<<<< does contain $2" $?
}
function test_help () {
reset
assertContains "$(./codecov -h)" "Global report uploading tool for Codecov"
assertNotContains "$(./codecov -h)" "Searching for coverage reports"
}
function test_fixes () {
reset
res=$(./codecov -d)
while read l; do
assertContains "$res" "$l"
done <ignores/results.txt
}
# ------------
# Test Options
# ------------
function test_url_opt () {
reset
res=$(./codecov -d -u http://example.com | grep "http://example.com/")
diff <(echo "http://example.com/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
function test_url_env () {
reset
res=$(CODECOV_URL="http://other.com" ./codecov -d | grep "http://other.com/")
diff <(echo "http://other.com/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
function test_flags_opt () {
reset
res=$(./codecov -d -F f1 -F f2 | grep "https://codecov.io/")
diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=f1,f2&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
# function test_yaml_location () {
# reset
# echo 'codecov:
# url: http://other.com
# token: abc123
# slug: owner/repo
# ' > codecov.yml
# res=$(./codecov -d | grep "http://other.com/")
# diff <(echo "http://other.com/upload/v4?package=bash-tbd&token=abc123&branch=$_BRANCH&commit=$_SHA&build=&build_url=&tag=&slug=owner/repo&yaml=codecov.yml&service=&flags=&pr=&job=") <(echo "$res")
# assertTrue 'Expected output differs.' $?
# }
#
# function test_yaml_location_2 () {
# reset
# echo 'codecov:
# token: uuid
# ' > tests/.codecov.yml
# res=$(./codecov -d | grep "https://codecov.io/")
# diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=uuid&branch=$_BRANCH&commit=$_SHA&build=&build_url=&tag=&slug=codecov%2Fcodecov-bash&yaml=tests%2F.codecov.yml&service=&flags=&pr=&job=") <(echo "$res")
# assertTrue 'Expected output differs.' $?
# }
function test_build_arg () {
reset
res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=1.6&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
# function test_changes_merge_commit () {
# reset
# git commit --amend -m 'Merge 5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b into 2f85ca252d69d6c52484f0c4b2e8500498228398'
# res=$(./codecov -d -b 1.6 | grep "https://codecov.io/")
# diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=5d4123bcb99dd1bc9b5ae8b4271b39dbe4c3928b&build=&build_url=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
# assertTrue 'Expected output differs.' $?
# }
function test_bowerrc_empty () {
reset
mkdir bower_components
touch bower_components/file.md
res=$(./codecov -d | grep "bower_components/file.md")
rm -rf bower_components
assertEquals '' "$res"
}
function test_bowerrc () {
reset
echo '{"directory": "bower/"}' > .bowerrc
mkdir bower
touch bower/file.md
res=$(./codecov -d | grep "bower/file.md")
rm -rf bower
rm .bowerrc
assertEquals '' "$res"
}
function test_bowerrc_2 () {
reset
echo '{ "directory":
"bower/" }' > .bowerrc
mkdir bower
touch bower/file.md
res=$(./codecov -d | grep "bower/file.md")
rm -rf bower
rm .bowerrc
assertEquals '' "$res"
}
function test_env_opt () {
reset
res="$(BUILD_ID="apples" ./codecov -de BUILD_ID)"
assertContains "$res" 'BUILD_ID=apples'
res="$(COMMIT="abc" BUILD_ID="apples" ./codecov -de BUILD_ID,COMMIT)"
assertContains "$res" 'BUILD_ID=apples'
assertContains "$res" 'COMMIT=abc'
}
function test_env_env () {
reset
res="$(CODECOV_ENV="BUILD_ID" BUILD_ID="apples" ./codecov -d)"
assertContains "$res" 'BUILD_ID=apples'
res="$(CODECOV_ENV="BUILD_ID,COMMIT" COMMIT="abc" BUILD_ID="apples" ./codecov -d)"
assertContains "$res" 'BUILD_ID=apples'
assertContains "$res" 'COMMIT=abc'
}
function test_slug_opt () {
reset
res=$(./codecov -dr myowner/myrepo | grep "https://codecov.io/")
diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
function test_slug_env () {
reset
export CODECOV_SLUG="myowner/myrepo"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=&flags=&pr=&job="
}
function test_gcov () {
reset
./codecov -d -X gcov -K | grep '**> gcov disable'
assertTrue 'gcov was disabled' $?
}
function test_file_opt () {
reset
assertContains "$(./codecov -df temp/coverage.json -K)" "+ temp/coverage.json bytes=2"
}
function test_token_opt () {
reset
token="38cd42da-4df4-4760-a998-4ebeca536904"
res=$(./codecov -d -t "$token" | grep "https://codecov.io/")
diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=$token&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
function test_token_env () {
reset
res=$(CODECOV_TOKEN="38cd42da-4df4-4760-a998-4ebeca536904" ./codecov -d | grep "https://codecov.io/")
diff <(echo "https://codecov.io/upload/v4?package=bash-tbd&token=$token&branch=$_BRANCH&commit=$_SHA&build=&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=&flags=&pr=&job=") <(echo "$res")
assertTrue 'Expected output differs.' $?
}
# function test_upload () {
# reset
# export CI="true"
# export TRAVIS_JOB_ID="33116958"
# export TRAVIS="true"
# export TRAVIS_BRANCH="master"
# export TRAVIS_COMMIT="c739768fcac68144a3a6d82305b9c4106934d31a"
# export TRAVIS_REPO_SLUG='codecov/ci-repo'
# export TRAVIS_JOB_ID="33116958"
# export TRAVIS_PULL_REQUEST="false"
# export TRAVIS_JOB_NUMBER="4.1"
# res=$(./codecov)
# assertContains "$res" "Reports queued to"
# assertContains "$res" "http://codecov.io/github/codecov/ci-repo?ref=c739768fcac68144a3a6d82305b9c4106934d31a"
# }
# -----------------
# Test CI Companies
# -----------------
function assertURL () {
url=$(./codecov -d | grep 'https://codecov.io/')
diff <(echo "$1") <(echo "$url")
assertTrue 'Expected output differs.' $?
}
function test_travis () {
reset
export CI="true"
export TRAVIS_JOB_ID="33116958"
export TRAVIS="true"
export TRAVIS_BRANCH="master"
export TRAVIS_COMMIT="c739768fcac68144a3a6d82305b9c4106934d31a"
export TRAVIS_REPO_SLUG='codecov/ci-repo'
export TRAVIS_JOB_ID="33116958"
export TRAVIS_PULL_REQUEST="false"
export TRAVIS_JOB_NUMBER="4.1"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=master&commit=c739768fcac68144a3a6d82305b9c4106934d31a&build=4.1&build_url=&name=&tag=&slug=codecov%2Fci-repo&yaml=&service=travis&flags=&pr=false&job=33116958"
}
function test_jenkins (){
reset
export JENKINS_URL="something"
export GIT_BRANCH="develop"
export GIT_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
export BUILD_NUMBER="15.1"
export BUILD_URL="http://endpoint"
export WORKSPACE="."
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=15.1&build_url=http%3A%2F%2Fendpoint&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=jenkins&flags=&pr=&job="
}
function test_jenkins_blue (){
reset
export JENKINS_URL="something"
export BRANCH_NAME="develop"
export CHANGE_ID="1"
export GIT_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
export BUILD_NUMBER="15.1"
export BUILD_URL="http://endpoint"
export WORKSPACE="."
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=15.1&build_url=http%3A%2F%2Fendpoint&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=jenkins&flags=&pr=1&job="
}
function test_bitrise (){
reset
export CI="true"
export BITRISE_IO="true"
export BITRISE_GIT_BRANCH="develop"
export GIT_CLONE_COMMIT_HASH="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
export BITRISE_BUILD_NUMBER="15.1"
export BITRISE_PULL_REQUEST="1"
export BITRISE_BUILD_URL="http://endpoint"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=15.1&build_url=http%3A%2F%2Fendpoint&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=bitrise&flags=&pr=1&job="
}
function test_jenkins_vars (){
reset
export JENKINS_URL="something"
export ghprbSourceBranch="develop"
export ghprbActualCommit="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
export BUILD_NUMBER="15.1"
export BUILD_URL="http://endpoint"
export WORKSPACE="."
export ghprbPullId="5"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=15.1&build_url=http%3A%2F%2Fendpoint&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=jenkins&flags=&pr=5&job="
}
function test_codeship (){
reset
export CI="true"
export CI_NAME="codeship"
export CI_BRANCH="develop"
export CI_BUILD_NUMBER="12.1"
export CI_BUILD_URL="http://endpoint"
export CI_COMMIT_ID="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=12.1&build_url=http%3A%2F%2Fendpoint&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=codeship&flags=&pr=&job="
}
semaphore (){
reset
export CI="true"
export SEMAPHORE="true"
export SEMAPHORE_REPO_SLUG="myowner/myrepo"
export BRANCH_NAME="develop"
export SEMAPHORE_BUILD_NUMBER="8"
export SEMAPHORE_CURRENT_THREAD="2"
export REVISION="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=8&build_url=&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=semaphore&flags=&pr=&job=2"
}
function test_buildkite (){
reset
export CI="true"
export BUILDKITE="true"
export BUILDKITE_PROJECT_SLUG="myowner/myrepo"
export BUILDKITE_BRANCH="develop"
export BUILDKITE_BUILD_NUMBER="8"
export BUILDKITE_JOB_ID="1"
export BUILDKITE_BUILD_URL="http://buildkite"
export BUILDKITE_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=8&build_url=http%3A%2F%2Fbuildkite&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=buildkite&flags=&pr=&job=1"
}
function test_solano (){
reset
export TDDIUM="true"
export TDDIUM_CURRENT_BRANCH="develop"
export TDDIUM_TID="12311"
export TDDIUM_PR_ID="false"
export TDDIUM_CURRENT_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=12311&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=solano&flags=&pr=false&job="
}
function test_drone (){
reset
export CI="drone"
export DRONE_BRANCH="develop"
export DRONE_BUILD_NUMBER="7.5"
export DRONE_BUILD_LINK="http://drone"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=$_SHA&build=7.5&build_url=http%3A%2F%2Fdrone&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=drone.io&flags=&pr=&job="
}
function test_appveyor (){
reset
export CI="True"
export APPVEYOR="True"
export APPVEYOR_REPO_NAME="myowner/myrepo"
export APPVEYOR_REPO_BRANCH="develop"
export APPVEYOR_BUILD_VERSION="1.2.3"
export APPVEYOR_PULL_REQUEST_NUMBER="1"
export APPVEYOR_ACCOUNT_NAME="a"
export APPVEYOR_PROJECT_SLUG="b"
export APPVEYOR_JOB_ID="9r2qufuu8"
export APPVEYOR_REPO_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=9r2qufuu8&build_url=&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=appveyor&flags=&pr=1&job=a%2Fb%2F1.2.3"
}
function test_wercker (){
reset
export CI="true"
export WERCKER_GIT_BRANCH="develop"
export WERCKER_MAIN_PIPELINE_STARTED="12311"
export WERCKER_GIT_OWNER="myowner"
export WERCKER_GIT_REPOSITORY="myrepo"
export WERCKER_GIT_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=12311&build_url=&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=wercker&flags=&pr=&job="
}
function test_magnum (){
reset
export CI="true"
export MAGNUM="true"
export CI_BRANCH="develop"
export CI_BUILD_NUMBER="12311"
export CI_COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=12311&build_url=&name=&tag=&slug=codecov%2Fcodecov-bash&yaml=&service=magnum&flags=&pr=&job="
}
function test_shippable (){
reset
export SHIPPABLE="true"
export BRANCH="develop"
export BUILD_NUMBER="1.2"
export REPO_FULL_NAME="myowner/myrepo"
export BUILD_URL="http://shippable"
export PULL_REQUEST="2"
export COMMIT="180c0d097354fc1a451da8a3be5aba255f2ffd9f"
assertURL "https://codecov.io/upload/v4?package=bash-tbd&token=&branch=develop&commit=180c0d097354fc1a451da8a3be5aba255f2ffd9f&build=1.2&build_url=http%3A%2F%2Fshippable&name=&tag=&slug=myowner%2Fmyrepo&yaml=&service=shippable&flags=&pr=2&job="
}
# Call and Run all Tests
. "shunit2-2.1.6/src/shunit2"