3 94a3f4e9 2024-03-30 thomas # Copyright (c) 2024 Omar Polo <op@openbsd.org>
5 94a3f4e9 2024-03-30 thomas # Permission to use, copy, modify, and distribute this software for any
6 94a3f4e9 2024-03-30 thomas # purpose with or without fee is hereby granted, provided that the above
7 94a3f4e9 2024-03-30 thomas # copyright notice and this permission notice appear in all copies.
9 94a3f4e9 2024-03-30 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 94a3f4e9 2024-03-30 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 94a3f4e9 2024-03-30 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 94a3f4e9 2024-03-30 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 94a3f4e9 2024-03-30 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 94a3f4e9 2024-03-30 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 94a3f4e9 2024-03-30 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 94a3f4e9 2024-03-30 thomas . ../cmdline/common.sh
18 94a3f4e9 2024-03-30 thomas . ./common.sh
20 94a3f4e9 2024-03-30 thomas test_file_changed() {
21 94a3f4e9 2024-03-30 thomas local testroot=`test_init file_changed 1`
23 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
25 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
26 94a3f4e9 2024-03-30 thomas echo "got clone failed unexpectedly" >&2
27 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
31 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
33 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
34 94a3f4e9 2024-03-30 thomas echo "got checkout failed unexpectedly" >&2
35 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
39 94a3f4e9 2024-03-30 thomas echo "change alpha" > $testroot/wt/alpha
40 94a3f4e9 2024-03-30 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
41 94a3f4e9 2024-03-30 thomas local commit_id=`git_show_head $testroot/repo-clone`
42 94a3f4e9 2024-03-30 thomas local author_time=`git_show_author_time $testroot/repo-clone`
44 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
45 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
47 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
49 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
50 94a3f4e9 2024-03-30 thomas echo "got send failed unexpectedly" >&2
51 94a3f4e9 2024-03-30 thomas test_done "$testroot" "1"
55 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
57 94a3f4e9 2024-03-30 thomas d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
59 94a3f4e9 2024-03-30 thomas cat <<-EOF > $testroot/stdout.expected
60 94a3f4e9 2024-03-30 thomas POST / HTTP/1.1
61 94a3f4e9 2024-03-30 thomas Host: localhost:${GOTD_TEST_HTTP_PORT}
62 94a3f4e9 2024-03-30 thomas Content-Type: application/json
63 94a3f4e9 2024-03-30 thomas Content-Length: 224
64 94a3f4e9 2024-03-30 thomas User-Agent: got-notify-http/${GOT_VERSION_STR}
65 94a3f4e9 2024-03-30 thomas Connection: close
67 94a3f4e9 2024-03-30 thomas {"notifications":[{"short":false,"id":"$commit_id","author":"$GOT_AUTHOR","date":"$d","message":"make changes\n","diffstat":{},"changes":{}}]}
70 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
72 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
73 94a3f4e9 2024-03-30 thomas diff -u $testroot/stdout.expected $testroot/stdout
74 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
78 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
81 94a3f4e9 2024-03-30 thomas test_many_commits_not_summarized() {
82 94a3f4e9 2024-03-30 thomas local testroot=`test_init many_commits_not_summarized 1`
84 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
86 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
87 94a3f4e9 2024-03-30 thomas echo "got clone failed unexpectedly" >&2
88 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
92 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
94 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
95 94a3f4e9 2024-03-30 thomas echo "got checkout failed unexpectedly" >&2
96 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
100 94a3f4e9 2024-03-30 thomas for i in `seq 1 24`; do
101 94a3f4e9 2024-03-30 thomas echo "alpha $i" > $testroot/wt/alpha
102 94a3f4e9 2024-03-30 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
103 94a3f4e9 2024-03-30 thomas local commit_id=`git_show_head $testroot/repo-clone`
104 94a3f4e9 2024-03-30 thomas local author_time=`git_show_author_time $testroot/repo-clone`
105 94a3f4e9 2024-03-30 thomas d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
106 94a3f4e9 2024-03-30 thomas set -- "$@" "$commit_id $d"
109 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
110 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
112 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
114 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
115 94a3f4e9 2024-03-30 thomas echo "got send failed unexpectedly" >&2
116 94a3f4e9 2024-03-30 thomas test_done "$testroot" "1"
120 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
122 94a3f4e9 2024-03-30 thomas cat <<-EOF > $testroot/stdout.expected
123 94a3f4e9 2024-03-30 thomas POST / HTTP/1.1
124 94a3f4e9 2024-03-30 thomas Host: localhost:${GOTD_TEST_HTTP_PORT}
125 94a3f4e9 2024-03-30 thomas Content-Type: application/json
126 94a3f4e9 2024-03-30 thomas Content-Length: 4939
127 94a3f4e9 2024-03-30 thomas User-Agent: got-notify-http/${GOT_VERSION_STR}
128 94a3f4e9 2024-03-30 thomas Connection: close
132 94a3f4e9 2024-03-30 thomas printf '{"notifications":[' >> $testroot/stdout.expected
134 94a3f4e9 2024-03-30 thomas for i in `seq 1 24`; do
135 94a3f4e9 2024-03-30 thomas s=`pop_idx $i "$@"`
136 94a3f4e9 2024-03-30 thomas commit_id=$(echo $s | cut -d' ' -f1)
137 94a3f4e9 2024-03-30 thomas commit_time=$(echo $s | sed -e "s/^$commit_id //g")
138 94a3f4e9 2024-03-30 thomas printf '%s{"short":false,"id":"%s","author":"%s","date":"%s","message":"%s","diffstat":{},"changes":{}}' \
139 94a3f4e9 2024-03-30 thomas "$comma" "$commit_id" "$GOT_AUTHOR" "$commit_time" "make changes\n"
140 94a3f4e9 2024-03-30 thomas comma=","
141 94a3f4e9 2024-03-30 thomas done >> $testroot/stdout.expected
142 94a3f4e9 2024-03-30 thomas echo "]}" >> $testroot/stdout.expected
144 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
146 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
147 94a3f4e9 2024-03-30 thomas diff -u $testroot/stdout.expected $testroot/stdout
148 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
152 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
155 94a3f4e9 2024-03-30 thomas test_many_commits_summarized() {
156 94a3f4e9 2024-03-30 thomas local testroot=`test_init many_commits_summarized 1`
158 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
160 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
161 94a3f4e9 2024-03-30 thomas echo "got clone failed unexpectedly" >&2
162 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
166 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
168 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
169 94a3f4e9 2024-03-30 thomas echo "got checkout failed unexpectedly" >&2
170 94a3f4e9 2024-03-30 thomas test_done "$testroot" 1
174 94a3f4e9 2024-03-30 thomas for i in `seq 1 51`; do
175 94a3f4e9 2024-03-30 thomas echo "alpha $i" > $testroot/wt/alpha
176 94a3f4e9 2024-03-30 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
177 94a3f4e9 2024-03-30 thomas local commit_id=`git_show_head $testroot/repo-clone`
178 94a3f4e9 2024-03-30 thomas local short_commit_id=`trim_obj_id 33 $commit_id`
179 94a3f4e9 2024-03-30 thomas local author_time=`git_show_author_time $testroot/repo-clone`
180 94a3f4e9 2024-03-30 thomas d=`date -u -r $author_time +"%G-%m-%d"`
181 94a3f4e9 2024-03-30 thomas set -- "$@" "$short_commit_id $d"
184 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
185 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
187 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
189 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
190 94a3f4e9 2024-03-30 thomas echo "got send failed unexpectedly" >&2
191 94a3f4e9 2024-03-30 thomas test_done "$testroot" "1"
195 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
197 94a3f4e9 2024-03-30 thomas cat <<-EOF > $testroot/stdout.expected
198 94a3f4e9 2024-03-30 thomas POST / HTTP/1.1
199 94a3f4e9 2024-03-30 thomas Host: localhost:${GOTD_TEST_HTTP_PORT}
200 94a3f4e9 2024-03-30 thomas Content-Type: application/json
201 94a3f4e9 2024-03-30 thomas Content-Length: 4864
202 94a3f4e9 2024-03-30 thomas User-Agent: got-notify-http/${GOT_VERSION_STR}
203 94a3f4e9 2024-03-30 thomas Connection: close
207 94a3f4e9 2024-03-30 thomas printf '{"notifications":[' >> $testroot/stdout.expected
209 94a3f4e9 2024-03-30 thomas for i in `seq 1 51`; do
210 94a3f4e9 2024-03-30 thomas s=`pop_idx $i "$@"`
211 94a3f4e9 2024-03-30 thomas commit_id=$(echo $s | cut -d' ' -f1)
212 94a3f4e9 2024-03-30 thomas commit_time=$(echo $s | sed -e "s/^$commit_id //g")
213 94a3f4e9 2024-03-30 thomas printf '%s{"short":true,"id":"%s","author":"%s","date":"%s","message":"%s"}' \
214 94a3f4e9 2024-03-30 thomas "$comma" "$commit_id" "$GOT_AUTHOR_8" \
215 94a3f4e9 2024-03-30 thomas "$commit_time" "make changes"
216 94a3f4e9 2024-03-30 thomas comma=","
217 94a3f4e9 2024-03-30 thomas done >> $testroot/stdout.expected
218 94a3f4e9 2024-03-30 thomas echo "]}" >> $testroot/stdout.expected
220 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
222 94a3f4e9 2024-03-30 thomas if [ $ret -ne 0 ]; then
223 94a3f4e9 2024-03-30 thomas diff -u $testroot/stdout.expected $testroot/stdout
224 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
228 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
231 94a3f4e9 2024-03-30 thomas test_parseargs "$@"
232 94a3f4e9 2024-03-30 thomas run_test test_file_changed
233 94a3f4e9 2024-03-30 thomas run_test test_many_commits_not_summarized
234 94a3f4e9 2024-03-30 thomas run_test test_many_commits_summarized