Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2024 Omar Polo <op@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ../cmdline/common.sh
18 . ./common.sh
20 test_file_changed() {
21 local testroot=`test_init file_changed 1`
23 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
24 ret=$?
25 if [ $ret -ne 0 ]; then
26 echo "got clone failed unexpectedly" >&2
27 test_done "$testroot" 1
28 return 1
29 fi
31 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
32 ret=$?
33 if [ $ret -ne 0 ]; then
34 echo "got checkout failed unexpectedly" >&2
35 test_done "$testroot" 1
36 return 1
37 fi
39 echo "change alpha" > $testroot/wt/alpha
40 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
41 local commit_id=`git_show_head $testroot/repo-clone`
42 local author_time=`git_show_author_time $testroot/repo-clone`
44 timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
45 > $testroot/stdout &
47 got send -b main -q -r $testroot/repo-clone
48 ret=$?
49 if [ $ret -ne 0 ]; then
50 echo "got send failed unexpectedly" >&2
51 test_done "$testroot" "1"
52 return 1
53 fi
55 wait %1 # wait for the http "server"
57 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
59 touch "$testroot/stdout.expected"
60 ed -s "$testroot/stdout.expected" <<-EOF
61 a
62 {"notifications":[{
63 "type":"commit",
64 "short":false,
65 "id":"$commit_id",
66 "author":{
67 "full":"$GOT_AUTHOR",
68 "name":"$GIT_AUTHOR_NAME",
69 "mail":"$GIT_AUTHOR_EMAIL",
70 "user":"$GOT_AUTHOR_11"
71 },
72 "committer":{
73 "full":"$GOT_AUTHOR",
74 "name":"$GIT_AUTHOR_NAME",
75 "mail":"$GIT_AUTHOR_EMAIL",
76 "user":"$GOT_AUTHOR_11"
77 },
78 "date":"$d",
79 "short_message":"make changes",
80 "message":"make changes\n",
81 "diffstat":{
82 "files":[{
83 "action":"modified",
84 "file":"alpha",
85 "added":1,
86 "removed":1
87 }],
88 "total":{
89 "added":1,
90 "removed":1
91 }
92 }
93 }]}
94 .
95 ,j
96 w
97 EOF
99 cmp -s $testroot/stdout.expected $testroot/stdout
100 ret=$?
101 if [ $ret -ne 0 ]; then
102 diff -u $testroot/stdout.expected $testroot/stdout
103 test_done "$testroot" "$ret"
104 return 1
105 fi
107 test_done "$testroot" "$ret"
110 test_bad_utf8() {
111 local testroot=`test_init bad_utf8 1`
113 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
114 ret=$?
115 if [ $ret -ne 0 ]; then
116 echo "got clone failed unexpectedly" >&2
117 test_done "$testroot" 1
118 return 1
119 fi
121 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
122 ret=$?
123 if [ $ret -ne 0 ]; then
124 echo "got checkout failed unexpectedly" >&2
125 test_done "$testroot" 1
126 fi
128 # invalid utf8 sequence
129 commit_msg="make$(printf '\xED\xA0\x80')changes"
131 echo "changed" > $testroot/wt/alpha
132 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
133 local commit_id=`git_show_head $testroot/repo-clone`
134 local author_time=`git_show_author_time $testroot/repo-clone`
136 timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
137 > $testroot/stdout &
139 got send -b main -q -r $testroot/repo-clone
140 ret=$?
141 if [ $ret -ne 0 ]; then
142 echo "got send failed unexpectedly" >&2
143 test_done "$testroot" "1"
144 return 1
145 fi
147 wait %1 # wait for the http "server"
149 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
151 touch "$testroot/stdout.expected"
152 ed -s "$testroot/stdout.expected" <<-EOF
154 {"notifications":[{
155 "type":"commit",
156 "short":false,
157 "id":"$commit_id",
158 "author":{
159 "full":"$GOT_AUTHOR",
160 "name":"$GIT_AUTHOR_NAME",
161 "mail":"$GIT_AUTHOR_EMAIL",
162 "user":"$GOT_AUTHOR_11"
163 },
164 "committer":{
165 "full":"$GOT_AUTHOR",
166 "name":"$GIT_AUTHOR_NAME",
167 "mail":"$GIT_AUTHOR_EMAIL",
168 "user":"$GOT_AUTHOR_11"
169 },
170 "date":"$d",
171 "short_message":"make\uFFFD\uFFFDchanges",
172 "message":"make\uFFFD\uFFFDchanges\n",
173 "diffstat":{
174 "files":[{
175 "action":"modified",
176 "file":"alpha",
177 "added":1,
178 "removed":1
179 }],
180 "total":{
181 "added":1,
182 "removed":1
185 }]}
187 ,j
189 EOF
191 cmp -s $testroot/stdout.expected $testroot/stdout
192 ret=$?
193 if [ $ret -ne 0 ]; then
194 diff -u $testroot/stdout.expected $testroot/stdout
195 test_done "$testroot" "$ret"
196 return 1
197 fi
199 test_done "$testroot" "$ret"
202 test_many_commits_not_summarized() {
203 local testroot=`test_init many_commits_not_summarized 1`
205 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
206 ret=$?
207 if [ $ret -ne 0 ]; then
208 echo "got clone failed unexpectedly" >&2
209 test_done "$testroot" 1
210 return 1
211 fi
213 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
214 ret=$?
215 if [ $ret -ne 0 ]; then
216 echo "got checkout failed unexpectedly" >&2
217 test_done "$testroot" 1
218 return 1
219 fi
221 for i in `seq 1 24`; do
222 echo "alpha $i" > $testroot/wt/alpha
223 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
224 local commit_id=`git_show_head $testroot/repo-clone`
225 local author_time=`git_show_author_time $testroot/repo-clone`
226 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
227 set -- "$@" "$commit_id $d"
228 done
230 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
231 > $testroot/stdout &
233 got send -b main -q -r $testroot/repo-clone
234 ret=$?
235 if [ $ret -ne 0 ]; then
236 echo "got send failed unexpectedly" >&2
237 test_done "$testroot" "1"
238 return 1
239 fi
241 wait %1 # wait for the http "server"
243 printf '{"notifications":[' > $testroot/stdout.expected
244 comma=""
245 for i in `seq 1 24`; do
246 s=`pop_idx $i "$@"`
247 commit_id=$(echo $s | cut -d' ' -f1)
248 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
250 echo "$comma"
251 comma=','
253 cat <<-EOF
255 "type":"commit",
256 "short":false,
257 "id":"$commit_id",
258 "author":{
259 "full":"$GOT_AUTHOR",
260 "name":"$GIT_AUTHOR_NAME",
261 "mail":"$GIT_AUTHOR_EMAIL",
262 "user":"$GOT_AUTHOR_11"
263 },
264 "committer":{
265 "full":"$GOT_AUTHOR",
266 "name":"$GIT_AUTHOR_NAME",
267 "mail":"$GIT_AUTHOR_EMAIL",
268 "user":"$GOT_AUTHOR_11"
269 },
270 "date":"$commit_time",
271 "short_message":"make changes",
272 "message":"make changes\n",
273 "diffstat":{
274 "files":[{
275 "action":"modified",
276 "file":"alpha",
277 "added":1,
278 "removed":1
279 }],
280 "total":{
281 "added":1,
282 "removed":1
286 EOF
287 done >> $testroot/stdout.expected
288 echo "]}" >> $testroot/stdout.expected
289 ed -s "$testroot/stdout.expected" <<-EOF
290 ,j
292 EOF
294 cmp -s $testroot/stdout.expected $testroot/stdout
295 ret=$?
296 if [ $ret -ne 0 ]; then
297 diff -u $testroot/stdout.expected $testroot/stdout
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 test_done "$testroot" "$ret"
305 test_many_commits_summarized() {
306 local testroot=`test_init many_commits_summarized 1`
308 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
309 ret=$?
310 if [ $ret -ne 0 ]; then
311 echo "got clone failed unexpectedly" >&2
312 test_done "$testroot" 1
313 return 1
314 fi
316 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
317 ret=$?
318 if [ $ret -ne 0 ]; then
319 echo "got checkout failed unexpectedly" >&2
320 test_done "$testroot" 1
321 return 1
322 fi
324 for i in `seq 1 51`; do
325 echo "alpha $i" > $testroot/wt/alpha
326 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
327 local commit_id=`git_show_head $testroot/repo-clone`
328 local short_commit_id=`trim_obj_id 33 $commit_id`
329 local author_time=`git_show_author_time $testroot/repo-clone`
330 d=`date -u -r $author_time +"%G-%m-%d"`
331 set -- "$@" "$short_commit_id $d"
332 done
334 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
335 > $testroot/stdout &
337 got send -b main -q -r $testroot/repo-clone
338 ret=$?
339 if [ $ret -ne 0 ]; then
340 echo "got send failed unexpectedly" >&2
341 test_done "$testroot" "1"
342 return 1
343 fi
345 wait %1 # wait for the http "server"
347 printf '{"notifications":[' > $testroot/stdout.expected
348 comma=""
349 for i in `seq 1 51`; do
350 s=`pop_idx $i "$@"`
351 commit_id=$(echo $s | cut -d' ' -f1)
352 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
354 echo "$comma"
355 comma=','
357 cat <<-EOF
359 "type":"commit",
360 "short":true,
361 "id":"$commit_id",
362 "committer":{
363 "user":"$GOT_AUTHOR_8"
364 },
365 "date":"$commit_time",
366 "short_message":"make changes"
368 EOF
369 done >> $testroot/stdout.expected
370 echo "]}" >> $testroot/stdout.expected
371 ed -s "$testroot/stdout.expected" <<-EOF
372 ,j
374 EOF
376 cmp -s $testroot/stdout.expected $testroot/stdout
377 ret=$?
378 if [ $ret -ne 0 ]; then
379 diff -u $testroot/stdout.expected $testroot/stdout
380 test_done "$testroot" "$ret"
381 return 1
382 fi
384 test_done "$testroot" "$ret"
387 test_branch_created() {
388 local testroot=`test_init branch_created 1`
390 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
391 ret=$?
392 if [ $ret -ne 0 ]; then
393 echo "got clone failed unexpectedly" >&2
394 test_done "$testroot" 1
395 return 1
396 fi
398 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
399 ret=$?
400 if [ $ret -ne 0 ]; then
401 echo "got checkout failed unexpectedly" >&2
402 test_done "$testroot" 1
403 return 1
404 fi
406 (cd $testroot/wt && got branch newbranch > /dev/null)
408 echo "change alpha on branch" > $testroot/wt/alpha
409 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
410 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
411 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
413 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
414 > $testroot/stdout &
416 got send -b newbranch -q -r $testroot/repo-clone
417 ret=$?
418 if [ $ret -ne 0 ]; then
419 echo "got send failed unexpectedly" >&2
420 test_done "$testroot" "1"
421 return 1
422 fi
424 wait %1 # wait for the http "server"
426 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
428 # in the future it should contain something like this too
429 # {
430 # "type":"new-branch",
431 # "user":"${GOTD_DEVUSER}",
432 # "ref":"refs/heads/newbranch"
433 # },
435 touch "$testroot/stdout.expected"
436 ed -s "$testroot/stdout.expected" <<-EOF
438 {"notifications":[
440 "type":"commit",
441 "short":false,
442 "id":"$commit_id",
443 "author":{
444 "full":"$GOT_AUTHOR",
445 "name":"$GIT_AUTHOR_NAME",
446 "mail":"$GIT_AUTHOR_EMAIL",
447 "user":"$GOT_AUTHOR_11"
448 },
449 "committer":{
450 "full":"$GOT_AUTHOR",
451 "name":"$GIT_AUTHOR_NAME",
452 "mail":"$GIT_AUTHOR_EMAIL",
453 "user":"$GOT_AUTHOR_11"
454 },
455 "date":"$d",
456 "short_message":"newbranch",
457 "message":"newbranch\n",
458 "diffstat":{
459 "files":[{
460 "action":"modified",
461 "file":"alpha",
462 "added":1,
463 "removed":1
464 }],
465 "total":{
466 "added":1,
467 "removed":1
471 ]}
473 ,j
475 EOF
477 cmp -s $testroot/stdout.expected $testroot/stdout
478 ret=$?
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
482 return 1
483 fi
485 test_done "$testroot" "$ret"
488 test_branch_removed() {
489 local testroot=`test_init branch_removed 1`
491 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
492 ret=$?
493 if [ $ret -ne 0 ]; then
494 echo "got clone failed unexpectedly" >&2
495 test_done "$testroot" 1
496 return 1
497 fi
499 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
500 > $testroot/stdout &
502 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
504 got send -d newbranch -q -r $testroot/repo-clone
505 ret=$?
506 if [ $ret -ne 0 ]; then
507 echo "got send failed unexpectedly" >&2
508 test_done "$testroot" "1"
509 return 1
510 fi
512 wait %1 # wait for the http "server"
514 touch "$testroot/stdout.expected"
515 ed -s "$testroot/stdout.expected" <<-EOF
517 {"notifications":[{
518 "type":"branch-deleted",
519 "ref":"refs/heads/newbranch",
520 "id":"$commit_id"
521 }]}
523 ,j
525 EOF
527 cmp -s $testroot/stdout.expected $testroot/stdout
528 ret=$?
529 if [ $ret -ne 0 ]; then
530 diff -u $testroot/stdout.expected $testroot/stdout
531 test_done "$testroot" "$ret"
532 return 1
533 fi
535 test_done "$testroot" "$ret"
538 test_tag_created() {
539 local testroot=`test_init tag_created 1`
541 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
542 ret=$?
543 if [ $ret -ne 0 ]; then
544 echo "got clone failed unexpectedly" >&2
545 test_done "$testroot" 1
546 return 1
547 fi
549 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
550 local commit_id=`git_show_head $testroot/repo-clone`
551 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
553 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
554 >$testroot/stdout &
556 got send -t 1.0 -q -r $testroot/repo-clone
557 ret=$?
558 if [ $ret -ne 0 ]; then
559 echo "got send failed unexpectedly" >&2
560 test_done "$testroot" "1"
561 return 1
562 fi
564 wait %1 # wait for the http "server"
566 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
568 touch "$testroot/stdout.expected"
569 ed -s "$testroot/stdout.expected" <<-EOF
571 {"notifications":[{
572 "type":"tag",
573 "tag":"refs/tags/1.0",
574 "tagger":{
575 "full":"$GOT_AUTHOR",
576 "name":"$GIT_AUTHOR_NAME",
577 "mail":"$GIT_AUTHOR_EMAIL",
578 "user":"$GOT_AUTHOR_11"
579 },
580 "date":"$d",
581 "object":{
582 "type":"commit",
583 "id":"$commit_id"
584 },
585 "message":"new tag\n\n"
586 }]}
588 ,j
590 EOF
592 cmp -s $testroot/stdout.expected $testroot/stdout
593 ret=$?
594 if [ $ret -ne 0 ]; then
595 diff -u $testroot/stdout.expected $testroot/stdout
596 test_done "$testroot" "$ret"
597 return 1
598 fi
600 test_done "$testroot" "$ret"
603 test_tag_changed() {
604 local testroot=`test_init tag_changed 1`
606 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
607 ret=$?
608 if [ $ret -ne 0 ]; then
609 echo "got clone failed unexpectedly" >&2
610 test_done "$testroot" 1
611 return 1
612 fi
614 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 echo "got checkout failed unexpectedly" >&2
618 test_done "$testroot" 1
619 return 1
620 fi
622 echo "change alpha" > $testroot/wt/alpha
623 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
624 local commit_id=`git_show_head $testroot/repo-clone`
626 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
627 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
628 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
630 timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
631 > $testroot/stdout &
633 got send -f -t 1.0 -q -r $testroot/repo-clone
634 ret=$?
635 if [ $ret -ne 0 ]; then
636 echo "got send failed unexpectedly" >&2
637 test_done "$testroot" "1"
638 return 1
639 fi
641 wait %1 # wait for the http "server"
643 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
645 # XXX: at the moment this is exactly the same as the "new tag"
646 # notification
648 touch "$testroot/stdout.expected"
649 ed -s "$testroot/stdout.expected" <<-EOF
651 {"notifications":[{
652 "type":"tag",
653 "tag":"refs/tags/1.0",
654 "tagger":{
655 "full":"$GOT_AUTHOR",
656 "name":"$GIT_AUTHOR_NAME",
657 "mail":"$GIT_AUTHOR_EMAIL",
658 "user":"$GOT_AUTHOR_11"
659 },
660 "date":"$d",
661 "object":{
662 "type":"commit",
663 "id":"$commit_id"
664 },
665 "message":"new tag\n\n"
666 }]}
668 ,j
670 EOF
672 cmp -s $testroot/stdout.expected $testroot/stdout
673 ret=$?
674 if [ $ret -ne 0 ]; then
675 diff -u $testroot/stdout.expected $testroot/stdout
676 test_done "$testroot" "$ret"
677 return 1
678 fi
680 test_done "$testroot" "$ret"
683 test_parseargs "$@"
684 run_test test_file_changed
685 run_test test_bad_utf8
686 run_test test_many_commits_not_summarized
687 run_test test_many_commits_summarized
688 run_test test_branch_created
689 run_test test_branch_removed
690 run_test test_tag_created
691 run_test test_tag_changed