3 # Copyright (c) 2024 Omar Polo <op@openbsd.org>
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.
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
20 # flan:password encoded in base64
21 AUTH="ZmxhbjpwYXNzd29yZA=="
24 local testroot=`test_init file_changed 1`
26 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
28 if [ $ret -ne 0 ]; then
29 echo "got clone failed unexpectedly" >&2
30 test_done "$testroot" 1
34 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
36 if [ $ret -ne 0 ]; then
37 echo "got checkout failed unexpectedly" >&2
38 test_done "$testroot" 1
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 \
50 sleep 1 # server starts up
52 got send -b main -q -r $testroot/repo-clone
54 if [ $ret -ne 0 ]; then
55 echo "got send failed unexpectedly" >&2
56 test_done "$testroot" "1"
60 wait %1 # wait for the http "server"
62 touch "$testroot/stdout.expected"
63 ed -s "$testroot/stdout.expected" <<-EOF
69 "authenticated_user":"${GOTD_DEVUSER}",
73 "name":"$GIT_AUTHOR_NAME",
74 "mail":"$GIT_AUTHOR_EMAIL",
75 "user":"$GOT_AUTHOR_11"
79 "name":"$GIT_AUTHOR_NAME",
80 "mail":"$GIT_AUTHOR_EMAIL",
81 "user":"$GOT_AUTHOR_11"
84 "short_message":"make changes",
85 "message":"make changes\n",
104 cmp -s $testroot/stdout.expected $testroot/stdout
106 if [ $ret -ne 0 ]; then
107 diff -u $testroot/stdout.expected $testroot/stdout
108 test_done "$testroot" "$ret"
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 \
121 sleep 1 # server starts up
123 git -C $testroot/repo-clone push -q origin main
125 if [ $ret -ne 0 ]; then
126 echo "git push failed unexpectedly" >&2
127 test_done "$testroot" "1"
131 wait %1 # wait for the http "server"
133 echo -n > "$testroot/stdout.expected"
134 ed -s "$testroot/stdout.expected" <<-EOF
140 "authenticated_user":"${GOTD_DEVUSER}",
143 "full":"$GOT_AUTHOR",
144 "name":"$GIT_AUTHOR_NAME",
145 "mail":"$GIT_AUTHOR_EMAIL",
146 "user":"$GOT_AUTHOR_11"
149 "full":"$GOT_AUTHOR",
150 "name":"$GIT_AUTHOR_NAME",
151 "mail":"$GIT_AUTHOR_EMAIL",
152 "user":"$GOT_AUTHOR_11"
155 "short_message":"make more changes",
156 "message":"make more changes\n",
175 cmp -s $testroot/stdout.expected $testroot/stdout
177 if [ $ret -ne 0 ]; then
178 diff -u $testroot/stdout.expected $testroot/stdout
180 test_done "$testroot" "$ret"
184 local testroot=`test_init bad_utf8 1`
186 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
188 if [ $ret -ne 0 ]; then
189 echo "got clone failed unexpectedly" >&2
190 test_done "$testroot" 1
194 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
196 if [ $ret -ne 0 ]; then
197 echo "got checkout failed unexpectedly" >&2
198 test_done "$testroot" 1
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 \
212 sleep 1 # server starts up
214 got send -b main -q -r $testroot/repo-clone
216 if [ $ret -ne 0 ]; then
217 echo "got send failed unexpectedly" >&2
218 test_done "$testroot" "1"
222 wait %1 # wait for the http "server"
224 touch "$testroot/stdout.expected"
225 ed -s "$testroot/stdout.expected" <<-EOF
231 "authenticated_user":"${GOTD_DEVUSER}",
234 "full":"$GOT_AUTHOR",
235 "name":"$GIT_AUTHOR_NAME",
236 "mail":"$GIT_AUTHOR_EMAIL",
237 "user":"$GOT_AUTHOR_11"
240 "full":"$GOT_AUTHOR",
241 "name":"$GIT_AUTHOR_NAME",
242 "mail":"$GIT_AUTHOR_EMAIL",
243 "user":"$GOT_AUTHOR_11"
246 "short_message":"make\uFFFD\uFFFDchanges",
247 "message":"make\uFFFD\uFFFDchanges\n",
266 cmp -s $testroot/stdout.expected $testroot/stdout
268 if [ $ret -ne 0 ]; then
269 diff -u $testroot/stdout.expected $testroot/stdout
270 test_done "$testroot" "$ret"
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
282 if [ $ret -ne 0 ]; then
283 echo "got clone failed unexpectedly" >&2
284 test_done "$testroot" 1
288 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
290 if [ $ret -ne 0 ]; then
291 echo "got checkout failed unexpectedly" >&2
292 test_done "$testroot" 1
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"
304 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
307 sleep 1 # server starts up
309 got send -b main -q -r $testroot/repo-clone
311 if [ $ret -ne 0 ]; then
312 echo "got send failed unexpectedly" >&2
313 test_done "$testroot" "1"
317 wait %1 # wait for the http "server"
319 printf '{"notifications":[' > $testroot/stdout.expected
321 for i in `seq 1 24`; do
323 commit_id=$(echo $s | cut -d' ' -f1)
324 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
334 "authenticated_user":"${GOTD_DEVUSER}",
337 "full":"$GOT_AUTHOR",
338 "name":"$GIT_AUTHOR_NAME",
339 "mail":"$GIT_AUTHOR_EMAIL",
340 "user":"$GOT_AUTHOR_11"
343 "full":"$GOT_AUTHOR",
344 "name":"$GIT_AUTHOR_NAME",
345 "mail":"$GIT_AUTHOR_EMAIL",
346 "user":"$GOT_AUTHOR_11"
349 "short_message":"make changes",
350 "message":"make changes\n",
365 done >> $testroot/stdout.expected
366 echo "]}" >> $testroot/stdout.expected
367 ed -s "$testroot/stdout.expected" <<-EOF
372 cmp -s $testroot/stdout.expected $testroot/stdout
374 if [ $ret -ne 0 ]; then
375 diff -u $testroot/stdout.expected $testroot/stdout
376 test_done "$testroot" "$ret"
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
388 if [ $ret -ne 0 ]; then
389 echo "got clone failed unexpectedly" >&2
390 test_done "$testroot" 1
394 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
396 if [ $ret -ne 0 ]; then
397 echo "got checkout failed unexpectedly" >&2
398 test_done "$testroot" 1
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"
411 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
414 sleep 1 # server starts up
416 got send -b main -q -r $testroot/repo-clone
418 if [ $ret -ne 0 ]; then
419 echo "got send failed unexpectedly" >&2
420 test_done "$testroot" "1"
424 wait %1 # wait for the http "server"
426 printf '{"notifications":[' > $testroot/stdout.expected
428 for i in `seq 1 51`; do
430 commit_id=$(echo $s | cut -d' ' -f1)
431 commit_time=$(echo "$s" | cut -d' ' -f2)
441 "authenticated_user":"${GOTD_DEVUSER}",
444 "user":"$GOT_AUTHOR_8"
447 "short_message":"make changes"
450 done >> $testroot/stdout.expected
451 echo "]}" >> $testroot/stdout.expected
452 ed -s "$testroot/stdout.expected" <<-EOF
457 cmp -s $testroot/stdout.expected $testroot/stdout
459 if [ $ret -ne 0 ]; then
460 diff -u $testroot/stdout.expected $testroot/stdout
461 test_done "$testroot" "$ret"
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
473 if [ $ret -ne 0 ]; then
474 echo "got clone failed unexpectedly" >&2
475 test_done "$testroot" 1
479 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
481 if [ $ret -ne 0 ]; then
482 echo "got checkout failed unexpectedly" >&2
483 test_done "$testroot" 1
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" \
497 sleep 1 # server starts up
499 got send -b newbranch -q -r $testroot/repo-clone
501 if [ $ret -ne 0 ]; then
502 echo "got send failed unexpectedly" >&2
503 test_done "$testroot" "1"
507 wait %1 # wait for the http "server"
509 # in the future it should contain something like this too
511 # "type":"new-branch",
512 # "user":"${GOTD_DEVUSER}",
513 # "ref":"refs/heads/newbranch"
516 touch "$testroot/stdout.expected"
517 ed -s "$testroot/stdout.expected" <<-EOF
524 "authenticated_user":"${GOTD_DEVUSER}",
527 "full":"$GOT_AUTHOR",
528 "name":"$GIT_AUTHOR_NAME",
529 "mail":"$GIT_AUTHOR_EMAIL",
530 "user":"$GOT_AUTHOR_11"
533 "full":"$GOT_AUTHOR",
534 "name":"$GIT_AUTHOR_NAME",
535 "mail":"$GIT_AUTHOR_EMAIL",
536 "user":"$GOT_AUTHOR_11"
539 "short_message":"newbranch",
540 "message":"newbranch\n",
560 cmp -s $testroot/stdout.expected $testroot/stdout
562 if [ $ret -ne 0 ]; then
563 diff -u $testroot/stdout.expected $testroot/stdout
564 test_done "$testroot" "$ret"
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
576 if [ $ret -ne 0 ]; then
577 echo "got clone failed unexpectedly" >&2
578 test_done "$testroot" 1
582 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
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
591 if [ $ret -ne 0 ]; then
592 echo "got send failed unexpectedly" >&2
593 test_done "$testroot" "1"
597 wait %1 # wait for the http "server"
599 touch "$testroot/stdout.expected"
600 ed -s "$testroot/stdout.expected" <<-EOF
603 "type":"branch-deleted",
605 "authenticated_user":"${GOTD_DEVUSER}",
606 "ref":"refs/heads/newbranch",
614 cmp -s $testroot/stdout.expected $testroot/stdout
616 if [ $ret -ne 0 ]; then
617 diff -u $testroot/stdout.expected $testroot/stdout
618 test_done "$testroot" "$ret"
622 test_done "$testroot" "$ret"
626 local testroot=`test_init tag_created 1`
628 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
630 if [ $ret -ne 0 ]; then
631 echo "got clone failed unexpectedly" >&2
632 test_done "$testroot" 1
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" \
643 sleep 1 # server starts up
645 got send -t 1.0 -q -r $testroot/repo-clone
647 if [ $ret -ne 0 ]; then
648 echo "got send failed unexpectedly" >&2
649 test_done "$testroot" "1"
653 wait %1 # wait for the http "server"
655 touch "$testroot/stdout.expected"
656 ed -s "$testroot/stdout.expected" <<-EOF
661 "authenticated_user":"${GOTD_DEVUSER}",
662 "tag":"refs/tags/1.0",
664 "full":"$GOT_AUTHOR",
665 "name":"$GIT_AUTHOR_NAME",
666 "mail":"$GIT_AUTHOR_EMAIL",
667 "user":"$GOT_AUTHOR_11"
674 "message":"new tag\n\n"
681 cmp -s $testroot/stdout.expected $testroot/stdout
683 if [ $ret -ne 0 ]; then
684 diff -u $testroot/stdout.expected $testroot/stdout
685 test_done "$testroot" "$ret"
689 test_done "$testroot" "$ret"
693 local testroot=`test_init tag_changed 1`
695 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
697 if [ $ret -ne 0 ]; then
698 echo "got clone failed unexpectedly" >&2
699 test_done "$testroot" 1
703 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
705 if [ $ret -ne 0 ]; then
706 echo "got checkout failed unexpectedly" >&2
707 test_done "$testroot" 1
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" \
722 sleep 1 # server starts up
724 got send -f -t 1.0 -q -r $testroot/repo-clone
726 if [ $ret -ne 0 ]; then
727 echo "got send failed unexpectedly" >&2
728 test_done "$testroot" "1"
732 wait %1 # wait for the http "server"
734 # XXX: at the moment this is exactly the same as the "new tag"
737 touch "$testroot/stdout.expected"
738 ed -s "$testroot/stdout.expected" <<-EOF
743 "authenticated_user":"${GOTD_DEVUSER}",
744 "tag":"refs/tags/1.0",
746 "full":"$GOT_AUTHOR",
747 "name":"$GIT_AUTHOR_NAME",
748 "mail":"$GIT_AUTHOR_EMAIL",
749 "user":"$GOT_AUTHOR_11"
756 "message":"new tag\n\n"
763 cmp -s $testroot/stdout.expected $testroot/stdout
765 if [ $ret -ne 0 ]; then
766 diff -u $testroot/stdout.expected $testroot/stdout
767 test_done "$testroot" "$ret"
771 test_done "$testroot" "$ret"
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