Blame


1 94a3f4e9 2024-03-30 thomas #!/bin/sh
2 94a3f4e9 2024-03-30 thomas #
3 94a3f4e9 2024-03-30 thomas # Copyright (c) 2024 Omar Polo <op@openbsd.org>
4 94a3f4e9 2024-03-30 thomas #
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.
8 94a3f4e9 2024-03-30 thomas #
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.
16 94a3f4e9 2024-03-30 thomas
17 94a3f4e9 2024-03-30 thomas . ../cmdline/common.sh
18 94a3f4e9 2024-03-30 thomas . ./common.sh
19 94a3f4e9 2024-03-30 thomas
20 94a3f4e9 2024-03-30 thomas test_file_changed() {
21 94a3f4e9 2024-03-30 thomas local testroot=`test_init file_changed 1`
22 94a3f4e9 2024-03-30 thomas
23 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
24 94a3f4e9 2024-03-30 thomas ret=$?
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
28 94a3f4e9 2024-03-30 thomas return 1
29 94a3f4e9 2024-03-30 thomas fi
30 94a3f4e9 2024-03-30 thomas
31 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
32 94a3f4e9 2024-03-30 thomas ret=$?
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
36 94a3f4e9 2024-03-30 thomas return 1
37 94a3f4e9 2024-03-30 thomas fi
38 94a3f4e9 2024-03-30 thomas
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`
43 94a3f4e9 2024-03-30 thomas
44 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p $GOTD_TEST_HTTP_PORT \
45 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
46 94a3f4e9 2024-03-30 thomas
47 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
48 94a3f4e9 2024-03-30 thomas ret=$?
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"
52 94a3f4e9 2024-03-30 thomas return 1
53 94a3f4e9 2024-03-30 thomas fi
54 94a3f4e9 2024-03-30 thomas
55 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
56 94a3f4e9 2024-03-30 thomas
57 94a3f4e9 2024-03-30 thomas d=`date -u -r $author_time +"%a %b %e %X %Y UTC"`
58 94a3f4e9 2024-03-30 thomas
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
66 94a3f4e9 2024-03-30 thomas
67 94a3f4e9 2024-03-30 thomas {"notifications":[{"short":false,"id":"$commit_id","author":"$GOT_AUTHOR","date":"$d","message":"make changes\n","diffstat":{},"changes":{}}]}
68 94a3f4e9 2024-03-30 thomas EOF
69 94a3f4e9 2024-03-30 thomas
70 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
71 94a3f4e9 2024-03-30 thomas ret=$?
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"
75 94a3f4e9 2024-03-30 thomas return 1
76 94a3f4e9 2024-03-30 thomas fi
77 94a3f4e9 2024-03-30 thomas
78 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
79 94a3f4e9 2024-03-30 thomas }
80 94a3f4e9 2024-03-30 thomas
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`
83 94a3f4e9 2024-03-30 thomas
84 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
85 94a3f4e9 2024-03-30 thomas ret=$?
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
89 94a3f4e9 2024-03-30 thomas return 1
90 94a3f4e9 2024-03-30 thomas fi
91 94a3f4e9 2024-03-30 thomas
92 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
93 94a3f4e9 2024-03-30 thomas ret=$?
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
97 94a3f4e9 2024-03-30 thomas return 1
98 94a3f4e9 2024-03-30 thomas fi
99 94a3f4e9 2024-03-30 thomas
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"
107 94a3f4e9 2024-03-30 thomas done
108 94a3f4e9 2024-03-30 thomas
109 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
110 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
111 94a3f4e9 2024-03-30 thomas
112 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
113 94a3f4e9 2024-03-30 thomas ret=$?
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"
117 94a3f4e9 2024-03-30 thomas return 1
118 94a3f4e9 2024-03-30 thomas fi
119 94a3f4e9 2024-03-30 thomas
120 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
121 94a3f4e9 2024-03-30 thomas
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
129 94a3f4e9 2024-03-30 thomas
130 94a3f4e9 2024-03-30 thomas EOF
131 94a3f4e9 2024-03-30 thomas
132 94a3f4e9 2024-03-30 thomas printf '{"notifications":[' >> $testroot/stdout.expected
133 94a3f4e9 2024-03-30 thomas comma=""
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
143 94a3f4e9 2024-03-30 thomas
144 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
145 94a3f4e9 2024-03-30 thomas ret=$?
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"
149 94a3f4e9 2024-03-30 thomas return 1
150 94a3f4e9 2024-03-30 thomas fi
151 94a3f4e9 2024-03-30 thomas
152 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
153 94a3f4e9 2024-03-30 thomas }
154 94a3f4e9 2024-03-30 thomas
155 94a3f4e9 2024-03-30 thomas test_many_commits_summarized() {
156 94a3f4e9 2024-03-30 thomas local testroot=`test_init many_commits_summarized 1`
157 94a3f4e9 2024-03-30 thomas
158 94a3f4e9 2024-03-30 thomas got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
159 94a3f4e9 2024-03-30 thomas ret=$?
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
163 94a3f4e9 2024-03-30 thomas return 1
164 94a3f4e9 2024-03-30 thomas fi
165 94a3f4e9 2024-03-30 thomas
166 94a3f4e9 2024-03-30 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
167 94a3f4e9 2024-03-30 thomas ret=$?
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
171 94a3f4e9 2024-03-30 thomas return 1
172 94a3f4e9 2024-03-30 thomas fi
173 94a3f4e9 2024-03-30 thomas
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"
182 94a3f4e9 2024-03-30 thomas done
183 94a3f4e9 2024-03-30 thomas
184 94a3f4e9 2024-03-30 thomas timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \
185 94a3f4e9 2024-03-30 thomas > $testroot/stdout &
186 94a3f4e9 2024-03-30 thomas
187 94a3f4e9 2024-03-30 thomas got send -b main -q -r $testroot/repo-clone
188 94a3f4e9 2024-03-30 thomas ret=$?
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"
192 94a3f4e9 2024-03-30 thomas return 1
193 94a3f4e9 2024-03-30 thomas fi
194 94a3f4e9 2024-03-30 thomas
195 94a3f4e9 2024-03-30 thomas wait %1 # wait for the http "server"
196 94a3f4e9 2024-03-30 thomas
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
204 94a3f4e9 2024-03-30 thomas
205 94a3f4e9 2024-03-30 thomas EOF
206 94a3f4e9 2024-03-30 thomas
207 94a3f4e9 2024-03-30 thomas printf '{"notifications":[' >> $testroot/stdout.expected
208 94a3f4e9 2024-03-30 thomas comma=""
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
219 94a3f4e9 2024-03-30 thomas
220 94a3f4e9 2024-03-30 thomas cmp -s $testroot/stdout.expected $testroot/stdout
221 94a3f4e9 2024-03-30 thomas ret=$?
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"
225 94a3f4e9 2024-03-30 thomas return 1
226 94a3f4e9 2024-03-30 thomas fi
227 94a3f4e9 2024-03-30 thomas
228 94a3f4e9 2024-03-30 thomas test_done "$testroot" "$ret"
229 94a3f4e9 2024-03-30 thomas }
230 94a3f4e9 2024-03-30 thomas
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