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 touch "$testroot/stdout.expected"
61 ed -s "$testroot/stdout.expected" <<-EOF
62 a
63 {"notifications":[{
64 "type":"commit",
65 "short":false,
66 "repo":"test-repo",
67 "id":"$commit_id",
68 "author":{
69 "full":"$GOT_AUTHOR",
70 "name":"$GIT_AUTHOR_NAME",
71 "mail":"$GIT_AUTHOR_EMAIL",
72 "user":"$GOT_AUTHOR_11"
73 },
74 "committer":{
75 "full":"$GOT_AUTHOR",
76 "name":"$GIT_AUTHOR_NAME",
77 "mail":"$GIT_AUTHOR_EMAIL",
78 "user":"$GOT_AUTHOR_11"
79 },
80 "date":$author_time,
81 "short_message":"make changes",
82 "message":"make changes\n",
83 "diffstat":{
84 "files":[{
85 "action":"modified",
86 "file":"alpha",
87 "added":1,
88 "removed":1
89 }],
90 "total":{
91 "added":1,
92 "removed":1
93 }
94 }
95 }]}
96 .
97 ,j
98 w
99 EOF
101 cmp -s $testroot/stdout.expected $testroot/stdout
102 ret=$?
103 if [ $ret -ne 0 ]; then
104 diff -u $testroot/stdout.expected $testroot/stdout
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 test_done "$testroot" "$ret"
112 test_bad_utf8() {
113 local testroot=`test_init bad_utf8 1`
115 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
116 ret=$?
117 if [ $ret -ne 0 ]; then
118 echo "got clone failed unexpectedly" >&2
119 test_done "$testroot" 1
120 return 1
121 fi
123 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
124 ret=$?
125 if [ $ret -ne 0 ]; then
126 echo "got checkout failed unexpectedly" >&2
127 test_done "$testroot" 1
128 fi
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 \
139 > $testroot/stdout &
141 got send -b main -q -r $testroot/repo-clone
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "got send failed unexpectedly" >&2
145 test_done "$testroot" "1"
146 return 1
147 fi
149 wait %1 # wait for the http "server"
151 touch "$testroot/stdout.expected"
152 ed -s "$testroot/stdout.expected" <<-EOF
154 {"notifications":[{
155 "type":"commit",
156 "short":false,
157 "repo":"test-repo",
158 "id":"$commit_id",
159 "author":{
160 "full":"$GOT_AUTHOR",
161 "name":"$GIT_AUTHOR_NAME",
162 "mail":"$GIT_AUTHOR_EMAIL",
163 "user":"$GOT_AUTHOR_11"
164 },
165 "committer":{
166 "full":"$GOT_AUTHOR",
167 "name":"$GIT_AUTHOR_NAME",
168 "mail":"$GIT_AUTHOR_EMAIL",
169 "user":"$GOT_AUTHOR_11"
170 },
171 "date":$author_time,
172 "short_message":"make\uFFFD\uFFFDchanges",
173 "message":"make\uFFFD\uFFFDchanges\n",
174 "diffstat":{
175 "files":[{
176 "action":"modified",
177 "file":"alpha",
178 "added":1,
179 "removed":1
180 }],
181 "total":{
182 "added":1,
183 "removed":1
186 }]}
188 ,j
190 EOF
192 cmp -s $testroot/stdout.expected $testroot/stdout
193 ret=$?
194 if [ $ret -ne 0 ]; then
195 diff -u $testroot/stdout.expected $testroot/stdout
196 test_done "$testroot" "$ret"
197 return 1
198 fi
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
207 ret=$?
208 if [ $ret -ne 0 ]; then
209 echo "got clone failed unexpectedly" >&2
210 test_done "$testroot" 1
211 return 1
212 fi
214 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
215 ret=$?
216 if [ $ret -ne 0 ]; then
217 echo "got checkout failed unexpectedly" >&2
218 test_done "$testroot" 1
219 return 1
220 fi
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"
228 done
230 timeout 5 ./http-server -a $AUTH -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 "repo":"test-repo",
258 "id":"$commit_id",
259 "author":{
260 "full":"$GOT_AUTHOR",
261 "name":"$GIT_AUTHOR_NAME",
262 "mail":"$GIT_AUTHOR_EMAIL",
263 "user":"$GOT_AUTHOR_11"
264 },
265 "committer":{
266 "full":"$GOT_AUTHOR",
267 "name":"$GIT_AUTHOR_NAME",
268 "mail":"$GIT_AUTHOR_EMAIL",
269 "user":"$GOT_AUTHOR_11"
270 },
271 "date":$commit_time,
272 "short_message":"make changes",
273 "message":"make changes\n",
274 "diffstat":{
275 "files":[{
276 "action":"modified",
277 "file":"alpha",
278 "added":1,
279 "removed":1
280 }],
281 "total":{
282 "added":1,
283 "removed":1
287 EOF
288 done >> $testroot/stdout.expected
289 echo "]}" >> $testroot/stdout.expected
290 ed -s "$testroot/stdout.expected" <<-EOF
291 ,j
293 EOF
295 cmp -s $testroot/stdout.expected $testroot/stdout
296 ret=$?
297 if [ $ret -ne 0 ]; then
298 diff -u $testroot/stdout.expected $testroot/stdout
299 test_done "$testroot" "$ret"
300 return 1
301 fi
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
310 ret=$?
311 if [ $ret -ne 0 ]; then
312 echo "got clone failed unexpectedly" >&2
313 test_done "$testroot" 1
314 return 1
315 fi
317 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
318 ret=$?
319 if [ $ret -ne 0 ]; then
320 echo "got checkout failed unexpectedly" >&2
321 test_done "$testroot" 1
322 return 1
323 fi
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"
332 done
334 timeout 5 ./http-server -a $AUTH -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" | cut -d' ' -f2)
354 echo "$comma"
355 comma=','
357 cat <<-EOF
359 "type":"commit",
360 "short":true,
361 "repo":"test-repo",
362 "id":"$commit_id",
363 "committer":{
364 "user":"$GOT_AUTHOR_8"
365 },
366 "date":$commit_time,
367 "short_message":"make changes"
369 EOF
370 done >> $testroot/stdout.expected
371 echo "]}" >> $testroot/stdout.expected
372 ed -s "$testroot/stdout.expected" <<-EOF
373 ,j
375 EOF
377 cmp -s $testroot/stdout.expected $testroot/stdout
378 ret=$?
379 if [ $ret -ne 0 ]; then
380 diff -u $testroot/stdout.expected $testroot/stdout
381 test_done "$testroot" "$ret"
382 return 1
383 fi
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
392 ret=$?
393 if [ $ret -ne 0 ]; then
394 echo "got clone failed unexpectedly" >&2
395 test_done "$testroot" 1
396 return 1
397 fi
399 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
400 ret=$?
401 if [ $ret -ne 0 ]; then
402 echo "got checkout failed unexpectedly" >&2
403 test_done "$testroot" 1
404 return 1
405 fi
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" \
415 > $testroot/stdout &
417 got send -b newbranch -q -r $testroot/repo-clone
418 ret=$?
419 if [ $ret -ne 0 ]; then
420 echo "got send failed unexpectedly" >&2
421 test_done "$testroot" "1"
422 return 1
423 fi
425 wait %1 # wait for the http "server"
427 # in the future it should contain something like this too
428 # {
429 # "type":"new-branch",
430 # "user":"${GOTD_DEVUSER}",
431 # "ref":"refs/heads/newbranch"
432 # },
434 touch "$testroot/stdout.expected"
435 ed -s "$testroot/stdout.expected" <<-EOF
437 {"notifications":[
439 "type":"commit",
440 "short":false,
441 "repo":"test-repo",
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":$author_time,
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 -a $AUTH -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 "repo":"test-repo",
520 "ref":"refs/heads/newbranch",
521 "id":"$commit_id"
522 }]}
524 ,j
526 EOF
528 cmp -s $testroot/stdout.expected $testroot/stdout
529 ret=$?
530 if [ $ret -ne 0 ]; then
531 diff -u $testroot/stdout.expected $testroot/stdout
532 test_done "$testroot" "$ret"
533 return 1
534 fi
536 test_done "$testroot" "$ret"
539 test_tag_created() {
540 local testroot=`test_init tag_created 1`
542 got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
543 ret=$?
544 if [ $ret -ne 0 ]; then
545 echo "got clone failed unexpectedly" >&2
546 test_done "$testroot" 1
547 return 1
548 fi
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" \
555 >$testroot/stdout &
557 got send -t 1.0 -q -r $testroot/repo-clone
558 ret=$?
559 if [ $ret -ne 0 ]; then
560 echo "got send failed unexpectedly" >&2
561 test_done "$testroot" "1"
562 return 1
563 fi
565 wait %1 # wait for the http "server"
567 touch "$testroot/stdout.expected"
568 ed -s "$testroot/stdout.expected" <<-EOF
570 {"notifications":[{
571 "type":"tag",
572 "repo":"test-repo",
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":$tagger_time,
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 -a $AUTH -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 # XXX: at the moment this is exactly the same as the "new tag"
644 # notification
646 touch "$testroot/stdout.expected"
647 ed -s "$testroot/stdout.expected" <<-EOF
649 {"notifications":[{
650 "type":"tag",
651 "repo":"test-repo",
652 "tag":"refs/tags/1.0",
653 "tagger":{
654 "full":"$GOT_AUTHOR",
655 "name":"$GIT_AUTHOR_NAME",
656 "mail":"$GIT_AUTHOR_EMAIL",
657 "user":"$GOT_AUTHOR_11"
658 },
659 "date":$tagger_time,
660 "object":{
661 "type":"commit",
662 "id":"$commit_id"
663 },
664 "message":"new tag\n\n"
665 }]}
667 ,j
669 EOF
671 cmp -s $testroot/stdout.expected $testroot/stdout
672 ret=$?
673 if [ $ret -ne 0 ]; then
674 diff -u $testroot/stdout.expected $testroot/stdout
675 test_done "$testroot" "$ret"
676 return 1
677 fi
679 test_done "$testroot" "$ret"
682 test_parseargs "$@"
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