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 got send -b main -q -r $testroot/repo-clone
51 ret=$?
52 if [ $ret -ne 0 ]; then
53 echo "got send failed unexpectedly" >&2
54 test_done "$testroot" "1"
55 return 1
56 fi
58 wait %1 # wait for the http "server"
60 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
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 "id":"$commit_id",
70 "author":{
71 "full":"$GOT_AUTHOR",
72 "name":"$GIT_AUTHOR_NAME",
73 "mail":"$GIT_AUTHOR_EMAIL",
74 "user":"$GOT_AUTHOR_11"
75 },
76 "committer":{
77 "full":"$GOT_AUTHOR",
78 "name":"$GIT_AUTHOR_NAME",
79 "mail":"$GIT_AUTHOR_EMAIL",
80 "user":"$GOT_AUTHOR_11"
81 },
82 "date":"$d",
83 "short_message":"make changes",
84 "message":"make changes\n",
85 "diffstat":{
86 "files":[{
87 "action":"modified",
88 "file":"alpha",
89 "added":1,
90 "removed":1
91 }],
92 "total":{
93 "added":1,
94 "removed":1
95 }
96 }
97 }]}
98 .
99 ,j
101 EOF
103 cmp -s $testroot/stdout.expected $testroot/stdout
104 ret=$?
105 if [ $ret -ne 0 ]; then
106 diff -u $testroot/stdout.expected $testroot/stdout
107 test_done "$testroot" "$ret"
108 return 1
109 fi
111 test_done "$testroot" "$ret"
114 test_bad_utf8() {
115 local testroot=`test_init bad_utf8 1`
117 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
118 ret=$?
119 if [ $ret -ne 0 ]; then
120 echo "got clone failed unexpectedly" >&2
121 test_done "$testroot" 1
122 return 1
123 fi
125 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
126 ret=$?
127 if [ $ret -ne 0 ]; then
128 echo "got checkout failed unexpectedly" >&2
129 test_done "$testroot" 1
130 fi
132 # invalid utf8 sequence
133 commit_msg="make$(printf '\xED\xA0\x80')changes"
135 echo "changed" > $testroot/wt/alpha
136 (cd $testroot/wt && got commit -m "$commit_msg" > /dev/null)
137 local commit_id=`git_show_head $testroot/repo-clone`
138 local author_time=`git_show_author_time $testroot/repo-clone`
140 timeout 5 ./http-server -a $AUTH -p $GOTD_TEST_HTTP_PORT \
141 > $testroot/stdout &
143 got send -b main -q -r $testroot/repo-clone
144 ret=$?
145 if [ $ret -ne 0 ]; then
146 echo "got send failed unexpectedly" >&2
147 test_done "$testroot" "1"
148 return 1
149 fi
151 wait %1 # wait for the http "server"
153 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
155 touch "$testroot/stdout.expected"
156 ed -s "$testroot/stdout.expected" <<-EOF
158 {"notifications":[{
159 "type":"commit",
160 "short":false,
161 "repo":"test-repo",
162 "id":"$commit_id",
163 "author":{
164 "full":"$GOT_AUTHOR",
165 "name":"$GIT_AUTHOR_NAME",
166 "mail":"$GIT_AUTHOR_EMAIL",
167 "user":"$GOT_AUTHOR_11"
168 },
169 "committer":{
170 "full":"$GOT_AUTHOR",
171 "name":"$GIT_AUTHOR_NAME",
172 "mail":"$GIT_AUTHOR_EMAIL",
173 "user":"$GOT_AUTHOR_11"
174 },
175 "date":"$d",
176 "short_message":"make\uFFFD\uFFFDchanges",
177 "message":"make\uFFFD\uFFFDchanges\n",
178 "diffstat":{
179 "files":[{
180 "action":"modified",
181 "file":"alpha",
182 "added":1,
183 "removed":1
184 }],
185 "total":{
186 "added":1,
187 "removed":1
190 }]}
192 ,j
194 EOF
196 cmp -s $testroot/stdout.expected $testroot/stdout
197 ret=$?
198 if [ $ret -ne 0 ]; then
199 diff -u $testroot/stdout.expected $testroot/stdout
200 test_done "$testroot" "$ret"
201 return 1
202 fi
204 test_done "$testroot" "$ret"
207 test_many_commits_not_summarized() {
208 local testroot=`test_init many_commits_not_summarized 1`
210 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
211 ret=$?
212 if [ $ret -ne 0 ]; then
213 echo "got clone failed unexpectedly" >&2
214 test_done "$testroot" 1
215 return 1
216 fi
218 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
219 ret=$?
220 if [ $ret -ne 0 ]; then
221 echo "got checkout failed unexpectedly" >&2
222 test_done "$testroot" 1
223 return 1
224 fi
226 for i in `seq 1 24`; do
227 echo "alpha $i" > $testroot/wt/alpha
228 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
229 local commit_id=`git_show_head $testroot/repo-clone`
230 local author_time=`git_show_author_time $testroot/repo-clone`
231 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
232 set -- "$@" "$commit_id $d"
233 done
235 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
236 > $testroot/stdout &
238 got send -b main -q -r $testroot/repo-clone
239 ret=$?
240 if [ $ret -ne 0 ]; then
241 echo "got send failed unexpectedly" >&2
242 test_done "$testroot" "1"
243 return 1
244 fi
246 wait %1 # wait for the http "server"
248 printf '{"notifications":[' > $testroot/stdout.expected
249 comma=""
250 for i in `seq 1 24`; do
251 s=`pop_idx $i "$@"`
252 commit_id=$(echo $s | cut -d' ' -f1)
253 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
255 echo "$comma"
256 comma=','
258 cat <<-EOF
260 "type":"commit",
261 "short":false,
262 "repo":"test-repo",
263 "id":"$commit_id",
264 "author":{
265 "full":"$GOT_AUTHOR",
266 "name":"$GIT_AUTHOR_NAME",
267 "mail":"$GIT_AUTHOR_EMAIL",
268 "user":"$GOT_AUTHOR_11"
269 },
270 "committer":{
271 "full":"$GOT_AUTHOR",
272 "name":"$GIT_AUTHOR_NAME",
273 "mail":"$GIT_AUTHOR_EMAIL",
274 "user":"$GOT_AUTHOR_11"
275 },
276 "date":"$commit_time",
277 "short_message":"make changes",
278 "message":"make changes\n",
279 "diffstat":{
280 "files":[{
281 "action":"modified",
282 "file":"alpha",
283 "added":1,
284 "removed":1
285 }],
286 "total":{
287 "added":1,
288 "removed":1
292 EOF
293 done >> $testroot/stdout.expected
294 echo "]}" >> $testroot/stdout.expected
295 ed -s "$testroot/stdout.expected" <<-EOF
296 ,j
298 EOF
300 cmp -s $testroot/stdout.expected $testroot/stdout
301 ret=$?
302 if [ $ret -ne 0 ]; then
303 diff -u $testroot/stdout.expected $testroot/stdout
304 test_done "$testroot" "$ret"
305 return 1
306 fi
308 test_done "$testroot" "$ret"
311 test_many_commits_summarized() {
312 local testroot=`test_init many_commits_summarized 1`
314 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
315 ret=$?
316 if [ $ret -ne 0 ]; then
317 echo "got clone failed unexpectedly" >&2
318 test_done "$testroot" 1
319 return 1
320 fi
322 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
323 ret=$?
324 if [ $ret -ne 0 ]; then
325 echo "got checkout failed unexpectedly" >&2
326 test_done "$testroot" 1
327 return 1
328 fi
330 for i in `seq 1 51`; do
331 echo "alpha $i" > $testroot/wt/alpha
332 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
333 local commit_id=`git_show_head $testroot/repo-clone`
334 local short_commit_id=`trim_obj_id 33 $commit_id`
335 local author_time=`git_show_author_time $testroot/repo-clone`
336 d=`date -u -r $author_time +"%G-%m-%d"`
337 set -- "$@" "$short_commit_id $d"
338 done
340 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
341 > $testroot/stdout &
343 got send -b main -q -r $testroot/repo-clone
344 ret=$?
345 if [ $ret -ne 0 ]; then
346 echo "got send failed unexpectedly" >&2
347 test_done "$testroot" "1"
348 return 1
349 fi
351 wait %1 # wait for the http "server"
353 printf '{"notifications":[' > $testroot/stdout.expected
354 comma=""
355 for i in `seq 1 51`; do
356 s=`pop_idx $i "$@"`
357 commit_id=$(echo $s | cut -d' ' -f1)
358 commit_time=$(echo "$s" | sed -e "s/^$commit_id //g")
360 echo "$comma"
361 comma=','
363 cat <<-EOF
365 "type":"commit",
366 "short":true,
367 "repo":"test-repo",
368 "id":"$commit_id",
369 "committer":{
370 "user":"$GOT_AUTHOR_8"
371 },
372 "date":"$commit_time",
373 "short_message":"make changes"
375 EOF
376 done >> $testroot/stdout.expected
377 echo "]}" >> $testroot/stdout.expected
378 ed -s "$testroot/stdout.expected" <<-EOF
379 ,j
381 EOF
383 cmp -s $testroot/stdout.expected $testroot/stdout
384 ret=$?
385 if [ $ret -ne 0 ]; then
386 diff -u $testroot/stdout.expected $testroot/stdout
387 test_done "$testroot" "$ret"
388 return 1
389 fi
391 test_done "$testroot" "$ret"
394 test_branch_created() {
395 local testroot=`test_init branch_created 1`
397 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
398 ret=$?
399 if [ $ret -ne 0 ]; then
400 echo "got clone failed unexpectedly" >&2
401 test_done "$testroot" 1
402 return 1
403 fi
405 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
406 ret=$?
407 if [ $ret -ne 0 ]; then
408 echo "got checkout failed unexpectedly" >&2
409 test_done "$testroot" 1
410 return 1
411 fi
413 (cd $testroot/wt && got branch newbranch > /dev/null)
415 echo "change alpha on branch" > $testroot/wt/alpha
416 (cd $testroot/wt && got commit -m 'newbranch' > /dev/null)
417 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
418 local author_time=`git_show_author_time $testroot/repo-clone $commit_id`
420 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
421 > $testroot/stdout &
423 got send -b newbranch -q -r $testroot/repo-clone
424 ret=$?
425 if [ $ret -ne 0 ]; then
426 echo "got send failed unexpectedly" >&2
427 test_done "$testroot" "1"
428 return 1
429 fi
431 wait %1 # wait for the http "server"
433 d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
435 # in the future it should contain something like this too
436 # {
437 # "type":"new-branch",
438 # "user":"${GOTD_DEVUSER}",
439 # "ref":"refs/heads/newbranch"
440 # },
442 touch "$testroot/stdout.expected"
443 ed -s "$testroot/stdout.expected" <<-EOF
445 {"notifications":[
447 "type":"commit",
448 "short":false,
449 "repo":"test-repo",
450 "id":"$commit_id",
451 "author":{
452 "full":"$GOT_AUTHOR",
453 "name":"$GIT_AUTHOR_NAME",
454 "mail":"$GIT_AUTHOR_EMAIL",
455 "user":"$GOT_AUTHOR_11"
456 },
457 "committer":{
458 "full":"$GOT_AUTHOR",
459 "name":"$GIT_AUTHOR_NAME",
460 "mail":"$GIT_AUTHOR_EMAIL",
461 "user":"$GOT_AUTHOR_11"
462 },
463 "date":"$d",
464 "short_message":"newbranch",
465 "message":"newbranch\n",
466 "diffstat":{
467 "files":[{
468 "action":"modified",
469 "file":"alpha",
470 "added":1,
471 "removed":1
472 }],
473 "total":{
474 "added":1,
475 "removed":1
479 ]}
481 ,j
483 EOF
485 cmp -s $testroot/stdout.expected $testroot/stdout
486 ret=$?
487 if [ $ret -ne 0 ]; then
488 diff -u $testroot/stdout.expected $testroot/stdout
489 test_done "$testroot" "$ret"
490 return 1
491 fi
493 test_done "$testroot" "$ret"
496 test_branch_removed() {
497 local testroot=`test_init branch_removed 1`
499 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
500 ret=$?
501 if [ $ret -ne 0 ]; then
502 echo "got clone failed unexpectedly" >&2
503 test_done "$testroot" 1
504 return 1
505 fi
507 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
508 > $testroot/stdout &
510 local commit_id=`git_show_branch_head $testroot/repo-clone newbranch`
512 got send -d newbranch -q -r $testroot/repo-clone
513 ret=$?
514 if [ $ret -ne 0 ]; then
515 echo "got send failed unexpectedly" >&2
516 test_done "$testroot" "1"
517 return 1
518 fi
520 wait %1 # wait for the http "server"
522 touch "$testroot/stdout.expected"
523 ed -s "$testroot/stdout.expected" <<-EOF
525 {"notifications":[{
526 "type":"branch-deleted",
527 "repo":"test-repo",
528 "ref":"refs/heads/newbranch",
529 "id":"$commit_id"
530 }]}
532 ,j
534 EOF
536 cmp -s $testroot/stdout.expected $testroot/stdout
537 ret=$?
538 if [ $ret -ne 0 ]; then
539 diff -u $testroot/stdout.expected $testroot/stdout
540 test_done "$testroot" "$ret"
541 return 1
542 fi
544 test_done "$testroot" "$ret"
547 test_tag_created() {
548 local testroot=`test_init tag_created 1`
550 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
551 ret=$?
552 if [ $ret -ne 0 ]; then
553 echo "got clone failed unexpectedly" >&2
554 test_done "$testroot" 1
555 return 1
556 fi
558 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
559 local commit_id=`git_show_head $testroot/repo-clone`
560 local tagger_time=`git_show_tagger_time $testroot/repo-clone 1.0`
562 timeout 5 ./http-server -a $AUTH -p "$GOTD_TEST_HTTP_PORT" \
563 >$testroot/stdout &
565 got send -t 1.0 -q -r $testroot/repo-clone
566 ret=$?
567 if [ $ret -ne 0 ]; then
568 echo "got send failed unexpectedly" >&2
569 test_done "$testroot" "1"
570 return 1
571 fi
573 wait %1 # wait for the http "server"
575 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
577 touch "$testroot/stdout.expected"
578 ed -s "$testroot/stdout.expected" <<-EOF
580 {"notifications":[{
581 "type":"tag",
582 "repo":"test-repo",
583 "tag":"refs/tags/1.0",
584 "tagger":{
585 "full":"$GOT_AUTHOR",
586 "name":"$GIT_AUTHOR_NAME",
587 "mail":"$GIT_AUTHOR_EMAIL",
588 "user":"$GOT_AUTHOR_11"
589 },
590 "date":"$d",
591 "object":{
592 "type":"commit",
593 "id":"$commit_id"
594 },
595 "message":"new tag\n\n"
596 }]}
598 ,j
600 EOF
602 cmp -s $testroot/stdout.expected $testroot/stdout
603 ret=$?
604 if [ $ret -ne 0 ]; then
605 diff -u $testroot/stdout.expected $testroot/stdout
606 test_done "$testroot" "$ret"
607 return 1
608 fi
610 test_done "$testroot" "$ret"
613 test_tag_changed() {
614 local testroot=`test_init tag_changed 1`
616 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
617 ret=$?
618 if [ $ret -ne 0 ]; then
619 echo "got clone failed unexpectedly" >&2
620 test_done "$testroot" 1
621 return 1
622 fi
624 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
625 ret=$?
626 if [ $ret -ne 0 ]; then
627 echo "got checkout failed unexpectedly" >&2
628 test_done "$testroot" 1
629 return 1
630 fi
632 echo "change alpha" > $testroot/wt/alpha
633 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
634 local commit_id=`git_show_head $testroot/repo-clone`
636 got ref -r $testroot/repo-clone -d refs/tags/1.0 >/dev/null
637 got tag -r $testroot/repo-clone -m "new tag" 1.0 > /dev/null
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 got send -f -t 1.0 -q -r $testroot/repo-clone
644 ret=$?
645 if [ $ret -ne 0 ]; then
646 echo "got send failed unexpectedly" >&2
647 test_done "$testroot" "1"
648 return 1
649 fi
651 wait %1 # wait for the http "server"
653 d=`date -u -r $tagger_time +"%a %b %e %X %Y UTC"`
655 # XXX: at the moment this is exactly the same as the "new tag"
656 # notification
658 touch "$testroot/stdout.expected"
659 ed -s "$testroot/stdout.expected" <<-EOF
661 {"notifications":[{
662 "type":"tag",
663 "repo":"test-repo",
664 "tag":"refs/tags/1.0",
665 "tagger":{
666 "full":"$GOT_AUTHOR",
667 "name":"$GIT_AUTHOR_NAME",
668 "mail":"$GIT_AUTHOR_EMAIL",
669 "user":"$GOT_AUTHOR_11"
670 },
671 "date":"$d",
672 "object":{
673 "type":"commit",
674 "id":"$commit_id"
675 },
676 "message":"new tag\n\n"
677 }]}
679 ,j
681 EOF
683 cmp -s $testroot/stdout.expected $testroot/stdout
684 ret=$?
685 if [ $ret -ne 0 ]; then
686 diff -u $testroot/stdout.expected $testroot/stdout
687 test_done "$testroot" "$ret"
688 return 1
689 fi
691 test_done "$testroot" "$ret"
694 test_parseargs "$@"
695 run_test test_file_changed
696 run_test test_bad_utf8
697 run_test test_many_commits_not_summarized
698 run_test test_many_commits_summarized
699 run_test test_branch_created
700 run_test test_branch_removed
701 run_test test_tag_created
702 run_test test_tag_changed