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 got send -b main -q -r $testroot/repo-clone
52 if [ $ret -ne 0 ]; then
53 echo "got send failed unexpectedly" >&2
54 test_done "$testroot" "1"
58 wait %1 # wait for the http "server"
60 touch "$testroot/stdout.expected"
61 ed -s "$testroot/stdout.expected" <<-EOF
70 "name":"$GIT_AUTHOR_NAME",
71 "mail":"$GIT_AUTHOR_EMAIL",
72 "user":"$GOT_AUTHOR_11"
76 "name":"$GIT_AUTHOR_NAME",
77 "mail":"$GIT_AUTHOR_EMAIL",
78 "user":"$GOT_AUTHOR_11"
81 "short_message":"make changes",
82 "message":"make changes\n",
101 cmp -s $testroot/stdout.expected $testroot/stdout
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
109 test_done "$testroot" "$ret"
113 local testroot=`test_init bad_utf8 1`
115 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
117 if [ $ret -ne 0 ]; then
118 echo "got clone failed unexpectedly" >&2
119 test_done "$testroot" 1
123 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
125 if [ $ret -ne 0 ]; then
126 echo "got checkout failed unexpectedly" >&2
127 test_done "$testroot" 1
130 # invalid utf8 sequence
131 commit_msg="make$(printf '\xED\xA0\x80')changes"
133 echo "changed" > $testroot/wt/alpha
134 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
135 local commit_id=`git_show_head $testroot/repo-clone`
136 local author_time=`git_show_author_time $testroot/repo-clone`
138 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
141 got send -b main -q -r $testroot/repo-clone
143 if [ $ret -ne 0 ]; then
144 echo "got send failed unexpectedly" >&2
145 test_done "$testroot" "1"
149 wait %1 # wait for the http "server"
151 touch "$testroot/stdout.expected"
152 ed -s "$testroot/stdout.expected" <<-EOF
160 "full":"$GOT_AUTHOR",
161 "name":"$GIT_AUTHOR_NAME",
162 "mail":"$GIT_AUTHOR_EMAIL",
163 "user":"$GOT_AUTHOR_11"
166 "full":"$GOT_AUTHOR",
167 "name":"$GIT_AUTHOR_NAME",
168 "mail":"$GIT_AUTHOR_EMAIL",
169 "user":"$GOT_AUTHOR_11"
172 "short_message":"make\uFFFD\uFFFDchanges",
173 "message":"make\uFFFD\uFFFDchanges\n",
192 cmp -s $testroot/stdout.expected $testroot/stdout
194 if [ $ret -ne 0 ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 test_done "$testroot" "$ret"
200 test_done "$testroot" "$ret"
203 test_many_commits_not_summarized() {
204 local testroot=`test_init many_commits_not_summarized 1`
206 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
208 if [ $ret -ne 0 ]; then
209 echo "got clone failed unexpectedly" >&2
210 test_done "$testroot" 1
214 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
216 if [ $ret -ne 0 ]; then
217 echo "got checkout failed unexpectedly" >&2
218 test_done "$testroot" 1
222 for i in `seq 1 24`; do
223 echo "alpha $i" > $testroot/wt/alpha
224 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
225 local commit_id=`git_show_head $testroot/repo-clone`
226 local author_time=`git_show_author_time $testroot/repo-clone`
227 set -- "$@" "$commit_id $author_time"
230 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
233 got send -b main -q -r $testroot/repo-clone
235 if [ $ret -ne 0 ]; then
236 echo "got send failed unexpectedly" >&2
237 test_done "$testroot" "1"
241 wait %1 # wait for the http "server"
243 printf '{"notifications":[' > $testroot/stdout.expected
245 for i in `seq 1 24`; do
247 commit_id=$(echo $s | cut -d' ' -f1)
248 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
260 "full":"$GOT_AUTHOR",
261 "name":"$GIT_AUTHOR_NAME",
262 "mail":"$GIT_AUTHOR_EMAIL",
263 "user":"$GOT_AUTHOR_11"
266 "full":"$GOT_AUTHOR",
267 "name":"$GIT_AUTHOR_NAME",
268 "mail":"$GIT_AUTHOR_EMAIL",
269 "user":"$GOT_AUTHOR_11"
272 "short_message":"make changes",
273 "message":"make changes\n",
288 done >> $testroot/stdout.expected
289 echo "]}" >> $testroot/stdout.expected
290 ed -s "$testroot/stdout.expected" <<-EOF
295 cmp -s $testroot/stdout.expected $testroot/stdout
297 if [ $ret -ne 0 ]; then
298 diff -u $testroot/stdout.expected $testroot/stdout
299 test_done "$testroot" "$ret"
303 test_done "$testroot" "$ret"
306 test_many_commits_summarized() {
307 local testroot=`test_init many_commits_summarized 1`
309 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
311 if [ $ret -ne 0 ]; then
312 echo "got clone failed unexpectedly" >&2
313 test_done "$testroot" 1
317 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
319 if [ $ret -ne 0 ]; then
320 echo "got checkout failed unexpectedly" >&2
321 test_done "$testroot" 1
325 for i in `seq 1 51`; do
326 echo "alpha $i" > $testroot/wt/alpha
327 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
328 local commit_id=`git_show_head $testroot/repo-clone`
329 local short_commit_id=`trim_obj_id 33 $commit_id`
330 local author_time=`git_show_author_time $testroot/repo-clone`
331 set -- "$@" "$short_commit_id $author_time"
334 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
337 got send -b main -q -r $testroot/repo-clone
339 if [ $ret -ne 0 ]; then
340 echo "got send failed unexpectedly" >&2
341 test_done "$testroot" "1"
345 wait %1 # wait for the http "server"
347 printf '{"notifications":[' > $testroot/stdout.expected
349 for i in `seq 1 51`; do
351 commit_id=$(echo $s | cut -d' ' -f1)
352 commit_time=$(echo "$s" | cut -d' ' -f2)
364 "user":"$GOT_AUTHOR_8"
367 "short_message":"make changes"
370 done >> $testroot/stdout.expected
371 echo "]}" >> $testroot/stdout.expected
372 ed -s "$testroot/stdout.expected" <<-EOF
377 cmp -s $testroot/stdout.expected $testroot/stdout
379 if [ $ret -ne 0 ]; then
380 diff -u $testroot/stdout.expected $testroot/stdout
381 test_done "$testroot" "$ret"
385 test_done "$testroot" "$ret"
388 test_branch_created() {
389 local testroot=`test_init branch_created 1`
391 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
393 if [ $ret -ne 0 ]; then
394 echo "got clone failed unexpectedly" >&2
395 test_done "$testroot" 1
399 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
401 if [ $ret -ne 0 ]; then
402 echo "got checkout failed unexpectedly" >&2
403 test_done "$testroot" 1
407 (cd $testroot/wt && got branch newbranch > /dev/null)
409 echo "change alpha on branch" > $testroot/wt/alpha
410 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
411 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
412 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
414 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
417 got send -b newbranch -q -r $testroot/repo-clone
419 if [ $ret -ne 0 ]; then
420 echo "got send failed unexpectedly" >&2
421 test_done "$testroot" "1"
425 wait %1 # wait for the http "server"
427 # in the future it should contain something like this too
429 # "type":"new-branch",
430 # "user":"${GOTD_DEVUSER}",
431 # "ref":"refs/heads/newbranch"
434 touch "$testroot/stdout.expected"
435 ed -s "$testroot/stdout.expected" <<-EOF
444 "full":"$GOT_AUTHOR",
445 "name":"$GIT_AUTHOR_NAME",
446 "mail":"$GIT_AUTHOR_EMAIL",
447 "user":"$GOT_AUTHOR_11"
450 "full":"$GOT_AUTHOR",
451 "name":"$GIT_AUTHOR_NAME",
452 "mail":"$GIT_AUTHOR_EMAIL",
453 "user":"$GOT_AUTHOR_11"
456 "short_message":"newbranch",
457 "message":"newbranch\n",
477 cmp -s $testroot/stdout.expected $testroot/stdout
479 if [ $ret -ne 0 ]; then
480 diff -u $testroot/stdout.expected $testroot/stdout
481 test_done "$testroot" "$ret"
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
493 if [ $ret -ne 0 ]; then
494 echo "got clone failed unexpectedly" >&2
495 test_done "$testroot" 1
499 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
502 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
504 got send -d newbranch -q -r $testroot/repo-clone
506 if [ $ret -ne 0 ]; then
507 echo "got send failed unexpectedly" >&2
508 test_done "$testroot" "1"
512 wait %1 # wait for the http "server"
514 touch "$testroot/stdout.expected"
515 ed -s "$testroot/stdout.expected" <<-EOF
518 "type":"branch-deleted",
520 "ref":"refs/heads/newbranch",
528 cmp -s $testroot/stdout.expected $testroot/stdout
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
536 test_done "$testroot" "$ret"
540 local testroot=`test_init tag_created 1`
542 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
544 if [ $ret -ne 0 ]; then
545 echo "got clone failed unexpectedly" >&2
546 test_done "$testroot" 1
550 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
551 local commit_id=`git_show_head $testroot/repo-clone`
552 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
554 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
557 got send -t 1.0 -q -r $testroot/repo-clone
559 if [ $ret -ne 0 ]; then
560 echo "got send failed unexpectedly" >&2
561 test_done "$testroot" "1"
565 wait %1 # wait for the http "server"
567 touch "$testroot/stdout.expected"
568 ed -s "$testroot/stdout.expected" <<-EOF
573 "tag":"refs/tags/1.0",
575 "full":"$GOT_AUTHOR",
576 "name":"$GIT_AUTHOR_NAME",
577 "mail":"$GIT_AUTHOR_EMAIL",
578 "user":"$GOT_AUTHOR_11"
585 "message":"new tag\n\n"
592 cmp -s $testroot/stdout.expected $testroot/stdout
594 if [ $ret -ne 0 ]; then
595 diff -u $testroot/stdout.expected $testroot/stdout
596 test_done "$testroot" "$ret"
600 test_done "$testroot" "$ret"
604 local testroot=`test_init tag_changed 1`
606 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
608 if [ $ret -ne 0 ]; then
609 echo "got clone failed unexpectedly" >&2
610 test_done "$testroot" 1
614 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
616 if [ $ret -ne 0 ]; then
617 echo "got checkout failed unexpectedly" >&2
618 test_done "$testroot" 1
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 -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
633 got send -f -t 1.0 -q -r $testroot/repo-clone
635 if [ $ret -ne 0 ]; then
636 echo "got send failed unexpectedly" >&2
637 test_done "$testroot" "1"
641 wait %1 # wait for the http "server"
643 # XXX: at the moment this is exactly the same as the "new tag"
646 touch "$testroot/stdout.expected"
647 ed -s "$testroot/stdout.expected" <<-EOF
652 "tag":"refs/tags/1.0",
654 "full":"$GOT_AUTHOR",
655 "name":"$GIT_AUTHOR_NAME",
656 "mail":"$GIT_AUTHOR_EMAIL",
657 "user":"$GOT_AUTHOR_11"
664 "message":"new tag\n\n"
671 cmp -s $testroot/stdout.expected $testroot/stdout
673 if [ $ret -ne 0 ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
679 test_done "$testroot" "$ret"
683 run_test test_file_changed
684 run_test test_bad_utf8
685 run_test test_many_commits_not_summarized
686 run_test test_many_commits_summarized
687 run_test test_branch_created
688 run_test test_branch_removed
689 run_test test_tag_created
690 run_test test_tag_changed