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 # flan:password encoded in base64
21 AUTH="ZmxhbjpwYXNzd29yZA=="
23 test_file_changed() {
24 local testroot=`test_init file_changed 1`
26 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
27 ret=$?
28 if [ $ret -ne 0 ]; then
29 echo "got clone failed unexpectedly" >&2
30 test_done "$testroot" 1
31 return 1
32 fi
34 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
35 ret=$?
36 if [ $ret -ne 0 ]; then
37 echo "got checkout failed unexpectedly" >&2
38 test_done "$testroot" 1
39 return 1
40 fi
42 echo "change alpha" > $testroot/wt/alpha
43 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
44 local commit_id=`git_show_head $testroot/repo-clone`
45 local author_time=`git_show_author_time $testroot/repo-clone`
47 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
48 > $testroot/stdout &
50 sleep 1 # server starts up
52 got send -b main -q -r $testroot/repo-clone
53 ret=$?
54 if [ $ret -ne 0 ]; then
55 echo "got send failed unexpectedly" >&2
56 test_done "$testroot" "1"
57 return 1
58 fi
60 wait %1 # wait for the http "server"
62 touch "$testroot/stdout.expected"
63 ed -s "$testroot/stdout.expected" <<-EOF
64 a
65 {"notifications":[{
66 "type":"commit",
67 "short":false,
68 "repo":"test-repo",
69 "authenticated_user":"${GOTD_DEVUSER}",
70 "id":"$commit_id",
71 "author":{
72 "full":"$GOT_AUTHOR",
73 "name":"$GIT_AUTHOR_NAME",
74 "mail":"$GIT_AUTHOR_EMAIL",
75 "user":"$GOT_AUTHOR_11"
76 },
77 "committer":{
78 "full":"$GOT_AUTHOR",
79 "name":"$GIT_AUTHOR_NAME",
80 "mail":"$GIT_AUTHOR_EMAIL",
81 "user":"$GOT_AUTHOR_11"
82 },
83 "date":$author_time,
84 "short_message":"make changes",
85 "message":"make changes\n",
86 "diffstat":{
87 "files":[{
88 "action":"modified",
89 "file":"alpha",
90 "added":1,
91 "removed":1
92 }],
93 "total":{
94 "added":1,
95 "removed":1
96 }
97 }
98 }]}
99 .
100 ,j
102 EOF
104 cmp -s $testroot/stdout.expected $testroot/stdout
105 ret=$?
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
109 return 1
110 fi
112 # Try the same thing again with 'git push' instead of 'got send'
113 echo "change alpha once more" > $testroot/wt/alpha
114 (cd $testroot/wt && got commit -m 'make more changes' > /dev/null)
115 local commit_id=`git_show_head $testroot/repo-clone`
116 local author_time=`git_show_author_time $testroot/repo-clone`
118 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
119 > $testroot/stdout &
121 sleep 1 # server starts up
123 git -C $testroot/repo-clone push -q origin main
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 echo "git push failed unexpectedly" >&2
127 test_done "$testroot" "1"
128 return 1
129 fi
131 wait %1 # wait for the http "server"
133 echo -n > "$testroot/stdout.expected"
134 ed -s "$testroot/stdout.expected" <<-EOF
136 {"notifications":[{
137 "type":"commit",
138 "short":false,
139 "repo":"test-repo",
140 "authenticated_user":"${GOTD_DEVUSER}",
141 "id":"$commit_id",
142 "author":{
143 "full":"$GOT_AUTHOR",
144 "name":"$GIT_AUTHOR_NAME",
145 "mail":"$GIT_AUTHOR_EMAIL",
146 "user":"$GOT_AUTHOR_11"
147 },
148 "committer":{
149 "full":"$GOT_AUTHOR",
150 "name":"$GIT_AUTHOR_NAME",
151 "mail":"$GIT_AUTHOR_EMAIL",
152 "user":"$GOT_AUTHOR_11"
153 },
154 "date":$author_time,
155 "short_message":"make more changes",
156 "message":"make more changes\n",
157 "diffstat":{
158 "files":[{
159 "action":"modified",
160 "file":"alpha",
161 "added":1,
162 "removed":1
163 }],
164 "total":{
165 "added":1,
166 "removed":1
169 }]}
171 ,j
173 EOF
175 cmp -s $testroot/stdout.expected $testroot/stdout
176 ret=$?
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout
179 fi
180 test_done "$testroot" "$ret"
183 test_bad_utf8() {
184 local testroot=`test_init bad_utf8 1`
186 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
187 ret=$?
188 if [ $ret -ne 0 ]; then
189 echo "got clone failed unexpectedly" >&2
190 test_done "$testroot" 1
191 return 1
192 fi
194 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
195 ret=$?
196 if [ $ret -ne 0 ]; then
197 echo "got checkout failed unexpectedly" >&2
198 test_done "$testroot" 1
199 fi
201 # invalid utf8 sequence
202 commit_msg="make$(printf '\xED\xA0\x80')changes"
204 echo "changed" > $testroot/wt/alpha
205 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
206 local commit_id=`git_show_head $testroot/repo-clone`
207 local author_time=`git_show_author_time $testroot/repo-clone`
209 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
210 > $testroot/stdout &
212 sleep 1 # server starts up
214 got send -b main -q -r $testroot/repo-clone
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 echo "got send failed unexpectedly" >&2
218 test_done "$testroot" "1"
219 return 1
220 fi
222 wait %1 # wait for the http "server"
224 touch "$testroot/stdout.expected"
225 ed -s "$testroot/stdout.expected" <<-EOF
227 {"notifications":[{
228 "type":"commit",
229 "short":false,
230 "repo":"test-repo",
231 "authenticated_user":"${GOTD_DEVUSER}",
232 "id":"$commit_id",
233 "author":{
234 "full":"$GOT_AUTHOR",
235 "name":"$GIT_AUTHOR_NAME",
236 "mail":"$GIT_AUTHOR_EMAIL",
237 "user":"$GOT_AUTHOR_11"
238 },
239 "committer":{
240 "full":"$GOT_AUTHOR",
241 "name":"$GIT_AUTHOR_NAME",
242 "mail":"$GIT_AUTHOR_EMAIL",
243 "user":"$GOT_AUTHOR_11"
244 },
245 "date":$author_time,
246 "short_message":"make\uFFFD\uFFFDchanges",
247 "message":"make\uFFFD\uFFFDchanges\n",
248 "diffstat":{
249 "files":[{
250 "action":"modified",
251 "file":"alpha",
252 "added":1,
253 "removed":1
254 }],
255 "total":{
256 "added":1,
257 "removed":1
260 }]}
262 ,j
264 EOF
266 cmp -s $testroot/stdout.expected $testroot/stdout
267 ret=$?
268 if [ $ret -ne 0 ]; then
269 diff -u $testroot/stdout.expected $testroot/stdout
270 test_done "$testroot" "$ret"
271 return 1
272 fi
274 test_done "$testroot" "$ret"
277 test_many_commits_not_summarized() {
278 local testroot=`test_init many_commits_not_summarized 1`
280 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
281 ret=$?
282 if [ $ret -ne 0 ]; then
283 echo "got clone failed unexpectedly" >&2
284 test_done "$testroot" 1
285 return 1
286 fi
288 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
289 ret=$?
290 if [ $ret -ne 0 ]; then
291 echo "got checkout failed unexpectedly" >&2
292 test_done "$testroot" 1
293 return 1
294 fi
296 for i in `seq 1 24`; do
297 echo "alpha $i" > $testroot/wt/alpha
298 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
299 local commit_id=`git_show_head $testroot/repo-clone`
300 local author_time=`git_show_author_time $testroot/repo-clone`
301 set -- "$@" "$commit_id $author_time"
302 done
304 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
305 > $testroot/stdout &
307 sleep 1 # server starts up
309 got send -b main -q -r $testroot/repo-clone
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 echo "got send failed unexpectedly" >&2
313 test_done "$testroot" "1"
314 return 1
315 fi
317 wait %1 # wait for the http "server"
319 printf '{"notifications":[' > $testroot/stdout.expected
320 comma=""
321 for i in `seq 1 24`; do
322 s=`pop_idx $i "$@"`
323 commit_id=$(echo $s | cut -d' ' -f1)
324 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
326 echo "$comma"
327 comma=','
329 cat <<-EOF
331 "type":"commit",
332 "short":false,
333 "repo":"test-repo",
334 "authenticated_user":"${GOTD_DEVUSER}",
335 "id":"$commit_id",
336 "author":{
337 "full":"$GOT_AUTHOR",
338 "name":"$GIT_AUTHOR_NAME",
339 "mail":"$GIT_AUTHOR_EMAIL",
340 "user":"$GOT_AUTHOR_11"
341 },
342 "committer":{
343 "full":"$GOT_AUTHOR",
344 "name":"$GIT_AUTHOR_NAME",
345 "mail":"$GIT_AUTHOR_EMAIL",
346 "user":"$GOT_AUTHOR_11"
347 },
348 "date":$commit_time,
349 "short_message":"make changes",
350 "message":"make changes\n",
351 "diffstat":{
352 "files":[{
353 "action":"modified",
354 "file":"alpha",
355 "added":1,
356 "removed":1
357 }],
358 "total":{
359 "added":1,
360 "removed":1
364 EOF
365 done >> $testroot/stdout.expected
366 echo "]}" >> $testroot/stdout.expected
367 ed -s "$testroot/stdout.expected" <<-EOF
368 ,j
370 EOF
372 cmp -s $testroot/stdout.expected $testroot/stdout
373 ret=$?
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
377 return 1
378 fi
380 test_done "$testroot" "$ret"
383 test_many_commits_summarized() {
384 local testroot=`test_init many_commits_summarized 1`
386 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
387 ret=$?
388 if [ $ret -ne 0 ]; then
389 echo "got clone failed unexpectedly" >&2
390 test_done "$testroot" 1
391 return 1
392 fi
394 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
395 ret=$?
396 if [ $ret -ne 0 ]; then
397 echo "got checkout failed unexpectedly" >&2
398 test_done "$testroot" 1
399 return 1
400 fi
402 for i in `seq 1 51`; do
403 echo "alpha $i" > $testroot/wt/alpha
404 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
405 local commit_id=`git_show_head $testroot/repo-clone`
406 local short_commit_id=`trim_obj_id 33 $commit_id`
407 local author_time=`git_show_author_time $testroot/repo-clone`
408 set -- "$@" "$short_commit_id $author_time"
409 done
411 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
412 > $testroot/stdout &
414 sleep 1 # server starts up
416 got send -b main -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 printf '{"notifications":[' > $testroot/stdout.expected
427 comma=""
428 for i in `seq 1 51`; do
429 s=`pop_idx $i "$@"`
430 commit_id=$(echo $s | cut -d' ' -f1)
431 commit_time=$(echo "$s" | cut -d' ' -f2)
433 echo "$comma"
434 comma=','
436 cat <<-EOF
438 "type":"commit",
439 "short":true,
440 "repo":"test-repo",
441 "authenticated_user":"${GOTD_DEVUSER}",
442 "id":"$commit_id",
443 "committer":{
444 "user":"$GOT_AUTHOR_8"
445 },
446 "date":$commit_time,
447 "short_message":"make changes"
449 EOF
450 done >> $testroot/stdout.expected
451 echo "]}" >> $testroot/stdout.expected
452 ed -s "$testroot/stdout.expected" <<-EOF
453 ,j
455 EOF
457 cmp -s $testroot/stdout.expected $testroot/stdout
458 ret=$?
459 if [ $ret -ne 0 ]; then
460 diff -u $testroot/stdout.expected $testroot/stdout
461 test_done "$testroot" "$ret"
462 return 1
463 fi
465 test_done "$testroot" "$ret"
468 test_branch_created() {
469 local testroot=`test_init branch_created 1`
471 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
472 ret=$?
473 if [ $ret -ne 0 ]; then
474 echo "got clone failed unexpectedly" >&2
475 test_done "$testroot" 1
476 return 1
477 fi
479 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
480 ret=$?
481 if [ $ret -ne 0 ]; then
482 echo "got checkout failed unexpectedly" >&2
483 test_done "$testroot" 1
484 return 1
485 fi
487 (cd $testroot/wt && got branch newbranch > /dev/null)
489 echo "change alpha on branch" > $testroot/wt/alpha
490 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
491 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
492 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
494 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
495 > $testroot/stdout &
497 sleep 1 # server starts up
499 got send -b newbranch -q -r $testroot/repo-clone
500 ret=$?
501 if [ $ret -ne 0 ]; then
502 echo "got send failed unexpectedly" >&2
503 test_done "$testroot" "1"
504 return 1
505 fi
507 wait %1 # wait for the http "server"
509 # in the future it should contain something like this too
510 # {
511 # "type":"new-branch",
512 # "user":"${GOTD_DEVUSER}",
513 # "ref":"refs/heads/newbranch"
514 # },
516 touch "$testroot/stdout.expected"
517 ed -s "$testroot/stdout.expected" <<-EOF
519 {"notifications":[
521 "type":"commit",
522 "short":false,
523 "repo":"test-repo",
524 "authenticated_user":"${GOTD_DEVUSER}",
525 "id":"$commit_id",
526 "author":{
527 "full":"$GOT_AUTHOR",
528 "name":"$GIT_AUTHOR_NAME",
529 "mail":"$GIT_AUTHOR_EMAIL",
530 "user":"$GOT_AUTHOR_11"
531 },
532 "committer":{
533 "full":"$GOT_AUTHOR",
534 "name":"$GIT_AUTHOR_NAME",
535 "mail":"$GIT_AUTHOR_EMAIL",
536 "user":"$GOT_AUTHOR_11"
537 },
538 "date":$author_time,
539 "short_message":"newbranch",
540 "message":"newbranch\n",
541 "diffstat":{
542 "files":[{
543 "action":"modified",
544 "file":"alpha",
545 "added":1,
546 "removed":1
547 }],
548 "total":{
549 "added":1,
550 "removed":1
554 ]}
556 ,j
558 EOF
560 cmp -s $testroot/stdout.expected $testroot/stdout
561 ret=$?
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
565 return 1
566 fi
568 test_done "$testroot" "$ret"
571 test_branch_removed() {
572 local testroot=`test_init branch_removed 1`
574 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
575 ret=$?
576 if [ $ret -ne 0 ]; then
577 echo "got clone failed unexpectedly" >&2
578 test_done "$testroot" 1
579 return 1
580 fi
582 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
583 > $testroot/stdout &
585 sleep 1 # server starts up
587 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
589 got send -d newbranch -q -r $testroot/repo-clone
590 ret=$?
591 if [ $ret -ne 0 ]; then
592 echo "got send failed unexpectedly" >&2
593 test_done "$testroot" "1"
594 return 1
595 fi
597 wait %1 # wait for the http "server"
599 touch "$testroot/stdout.expected"
600 ed -s "$testroot/stdout.expected" <<-EOF
602 {"notifications":[{
603 "type":"branch-deleted",
604 "repo":"test-repo",
605 "authenticated_user":"${GOTD_DEVUSER}",
606 "ref":"refs/heads/newbranch",
607 "id":"$commit_id"
608 }]}
610 ,j
612 EOF
614 cmp -s $testroot/stdout.expected $testroot/stdout
615 ret=$?
616 if [ $ret -ne 0 ]; then
617 diff -u $testroot/stdout.expected $testroot/stdout
618 test_done "$testroot" "$ret"
619 return 1
620 fi
622 test_done "$testroot" "$ret"
625 test_tag_created() {
626 local testroot=`test_init tag_created 1`
628 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
629 ret=$?
630 if [ $ret -ne 0 ]; then
631 echo "got clone failed unexpectedly" >&2
632 test_done "$testroot" 1
633 return 1
634 fi
636 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
637 local commit_id=`git_show_head $testroot/repo-clone`
638 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
640 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
641 >$testroot/stdout &
643 sleep 1 # server starts up
645 got send -t 1.0 -q -r $testroot/repo-clone
646 ret=$?
647 if [ $ret -ne 0 ]; then
648 echo "got send failed unexpectedly" >&2
649 test_done "$testroot" "1"
650 return 1
651 fi
653 wait %1 # wait for the http "server"
655 touch "$testroot/stdout.expected"
656 ed -s "$testroot/stdout.expected" <<-EOF
658 {"notifications":[{
659 "type":"tag",
660 "repo":"test-repo",
661 "authenticated_user":"${GOTD_DEVUSER}",
662 "tag":"refs/tags/1.0",
663 "tagger":{
664 "full":"$GOT_AUTHOR",
665 "name":"$GIT_AUTHOR_NAME",
666 "mail":"$GIT_AUTHOR_EMAIL",
667 "user":"$GOT_AUTHOR_11"
668 },
669 "date":$tagger_time,
670 "object":{
671 "type":"commit",
672 "id":"$commit_id"
673 },
674 "message":"new tag\n\n"
675 }]}
677 ,j
679 EOF
681 cmp -s $testroot/stdout.expected $testroot/stdout
682 ret=$?
683 if [ $ret -ne 0 ]; then
684 diff -u $testroot/stdout.expected $testroot/stdout
685 test_done "$testroot" "$ret"
686 return 1
687 fi
689 test_done "$testroot" "$ret"
692 test_tag_changed() {
693 local testroot=`test_init tag_changed 1`
695 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
696 ret=$?
697 if [ $ret -ne 0 ]; then
698 echo "got clone failed unexpectedly" >&2
699 test_done "$testroot" 1
700 return 1
701 fi
703 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
704 ret=$?
705 if [ $ret -ne 0 ]; then
706 echo "got checkout failed unexpectedly" >&2
707 test_done "$testroot" 1
708 return 1
709 fi
711 echo "change alpha" > $testroot/wt/alpha
712 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
713 local commit_id=`git_show_head $testroot/repo-clone`
715 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
716 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
717 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
719 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
720 > $testroot/stdout &
722 sleep 1 # server starts up
724 got send -f -t 1.0 -q -r $testroot/repo-clone
725 ret=$?
726 if [ $ret -ne 0 ]; then
727 echo "got send failed unexpectedly" >&2
728 test_done "$testroot" "1"
729 return 1
730 fi
732 wait %1 # wait for the http "server"
734 # XXX: at the moment this is exactly the same as the "new tag"
735 # notification
737 touch "$testroot/stdout.expected"
738 ed -s "$testroot/stdout.expected" <<-EOF
740 {"notifications":[{
741 "type":"tag",
742 "repo":"test-repo",
743 "authenticated_user":"${GOTD_DEVUSER}",
744 "tag":"refs/tags/1.0",
745 "tagger":{
746 "full":"$GOT_AUTHOR",
747 "name":"$GIT_AUTHOR_NAME",
748 "mail":"$GIT_AUTHOR_EMAIL",
749 "user":"$GOT_AUTHOR_11"
750 },
751 "date":$tagger_time,
752 "object":{
753 "type":"commit",
754 "id":"$commit_id"
755 },
756 "message":"new tag\n\n"
757 }]}
759 ,j
761 EOF
763 cmp -s $testroot/stdout.expected $testroot/stdout
764 ret=$?
765 if [ $ret -ne 0 ]; then
766 diff -u $testroot/stdout.expected $testroot/stdout
767 test_done "$testroot" "$ret"
768 return 1
769 fi
771 test_done "$testroot" "$ret"
774 test_parseargs "$@"
775 run_test test_file_changed
776 run_test test_bad_utf8
777 run_test test_many_commits_not_summarized
778 run_test test_many_commits_summarized
779 run_test test_branch_created
780 run_test test_branch_removed
781 run_test test_tag_created
782 run_test test_tag_changed