Blame


1 4ce98cf7 2022-11-08 stsp #!/bin/sh
2 4ce98cf7 2022-11-08 stsp #
3 4ce98cf7 2022-11-08 stsp # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 4ce98cf7 2022-11-08 stsp #
5 4ce98cf7 2022-11-08 stsp # Permission to use, copy, modify, and distribute this software for any
6 4ce98cf7 2022-11-08 stsp # purpose with or without fee is hereby granted, provided that the above
7 4ce98cf7 2022-11-08 stsp # copyright notice and this permission notice appear in all copies.
8 4ce98cf7 2022-11-08 stsp #
9 4ce98cf7 2022-11-08 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 4ce98cf7 2022-11-08 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 4ce98cf7 2022-11-08 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 4ce98cf7 2022-11-08 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 4ce98cf7 2022-11-08 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 4ce98cf7 2022-11-08 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 4ce98cf7 2022-11-08 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 4ce98cf7 2022-11-08 stsp
17 4ce98cf7 2022-11-08 stsp . ../cmdline/common.sh
18 4ce98cf7 2022-11-08 stsp . ./common.sh
19 4ce98cf7 2022-11-08 stsp
20 4ce98cf7 2022-11-08 stsp test_send_empty() {
21 4ce98cf7 2022-11-08 stsp local testroot=`test_init send_empty`
22 4ce98cf7 2022-11-08 stsp local commit_id=`git_show_head $testroot/repo`
23 4ce98cf7 2022-11-08 stsp
24 4ce98cf7 2022-11-08 stsp (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
25 4ce98cf7 2022-11-08 stsp
26 4ce98cf7 2022-11-08 stsp # The gotd-controlled test repository starts out empty.
27 4ce98cf7 2022-11-08 stsp got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 4ce98cf7 2022-11-08 stsp echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 4ce98cf7 2022-11-08 stsp cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 4ce98cf7 2022-11-08 stsp ret=$?
31 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
32 4ce98cf7 2022-11-08 stsp diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
34 4ce98cf7 2022-11-08 stsp return 1
35 4ce98cf7 2022-11-08 stsp fi
36 4ce98cf7 2022-11-08 stsp
37 4ce98cf7 2022-11-08 stsp got checkout -q $testroot/repo $testroot/wt >/dev/null
38 4ce98cf7 2022-11-08 stsp ret=$?
39 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
40 4ce98cf7 2022-11-08 stsp echo "got checkout failed unexpectedly" >&2
41 c08cee54 2022-11-08 stsp test_done "$testroot" 1
42 4ce98cf7 2022-11-08 stsp return 1
43 4ce98cf7 2022-11-08 stsp fi
44 4ce98cf7 2022-11-08 stsp
45 4ce98cf7 2022-11-08 stsp # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 4ce98cf7 2022-11-08 stsp cat >> $testroot/wt/.got/got.conf <<EOF
47 4ce98cf7 2022-11-08 stsp remote "gotd" {
48 4ce98cf7 2022-11-08 stsp server ${GOTD_DEVUSER}@127.0.0.1
49 4ce98cf7 2022-11-08 stsp repository "test-repo"
50 4ce98cf7 2022-11-08 stsp protocol ssh
51 4ce98cf7 2022-11-08 stsp }
52 4ce98cf7 2022-11-08 stsp EOF
53 4ce98cf7 2022-11-08 stsp (cd $testroot/wt && got send -q -a gotd)
54 4ce98cf7 2022-11-08 stsp ret=$?
55 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
56 4ce98cf7 2022-11-08 stsp echo "got send failed unexpectedly" >&2
57 c08cee54 2022-11-08 stsp test_done "$testroot" 1
58 4ce98cf7 2022-11-08 stsp return 1
59 4ce98cf7 2022-11-08 stsp fi
60 4ce98cf7 2022-11-08 stsp
61 4ce98cf7 2022-11-08 stsp # Server should have created a new reference.
62 4ce98cf7 2022-11-08 stsp got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
63 4ce98cf7 2022-11-08 stsp cat > $testroot/ref-list.expected <<EOF
64 4ce98cf7 2022-11-08 stsp HEAD: refs/heads/main
65 4ce98cf7 2022-11-08 stsp refs/heads/master: $commit_id
66 4ce98cf7 2022-11-08 stsp EOF
67 4ce98cf7 2022-11-08 stsp cmp -s $testroot/ref-list.expected $testroot/ref-list.after
68 4ce98cf7 2022-11-08 stsp ret=$?
69 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
70 4ce98cf7 2022-11-08 stsp diff -u $testroot/ref-list.expected $testroot/ref-list.after
71 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
72 4ce98cf7 2022-11-08 stsp return 1
73 4ce98cf7 2022-11-08 stsp fi
74 4ce98cf7 2022-11-08 stsp
75 4ce98cf7 2022-11-08 stsp # Verify that the result can be cloned again.
76 4ce98cf7 2022-11-08 stsp # XXX need -b master at present because gotd does not rewrite HEAD
77 4ce98cf7 2022-11-08 stsp got clone -q -b master ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
78 4ce98cf7 2022-11-08 stsp ret=$?
79 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
80 4ce98cf7 2022-11-08 stsp echo "got clone failed unexpectedly" >&2
81 c08cee54 2022-11-08 stsp test_done "$testroot" 1
82 4ce98cf7 2022-11-08 stsp return 1
83 4ce98cf7 2022-11-08 stsp fi
84 4ce98cf7 2022-11-08 stsp
85 4ce98cf7 2022-11-08 stsp got tree -R -r $testroot/repo-clone2 > $testroot/stdout
86 4ce98cf7 2022-11-08 stsp cat > $testroot/stdout.expected <<EOF
87 4ce98cf7 2022-11-08 stsp alpha
88 4ce98cf7 2022-11-08 stsp beta
89 4ce98cf7 2022-11-08 stsp epsilon/
90 4ce98cf7 2022-11-08 stsp epsilon/zeta
91 4ce98cf7 2022-11-08 stsp gamma/
92 4ce98cf7 2022-11-08 stsp gamma/delta
93 4ce98cf7 2022-11-08 stsp EOF
94 4ce98cf7 2022-11-08 stsp cmp -s $testroot/stdout.expected $testroot/stdout
95 4ce98cf7 2022-11-08 stsp ret=$?
96 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
97 4ce98cf7 2022-11-08 stsp diff -u $testroot/stdout.expected $testroot/stdout
98 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
99 4ce98cf7 2022-11-08 stsp return 1
100 4ce98cf7 2022-11-08 stsp fi
101 4ce98cf7 2022-11-08 stsp
102 4ce98cf7 2022-11-08 stsp # sending to a repository should result in a new pack file
103 4ce98cf7 2022-11-08 stsp (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.after)
104 4ce98cf7 2022-11-08 stsp diff -u $testroot/repo-list.before $testroot/repo-list.after \
105 4ce98cf7 2022-11-08 stsp > $testroot/repo-list.diff
106 4ce98cf7 2022-11-08 stsp grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
107 c08cee54 2022-11-08 stsp nplus=`awk '/^\+[^+]/{c++} END{print c}' $testroot/repo-list.diff`
108 4ce98cf7 2022-11-08 stsp if [ "$nplus" != "4" ]; then
109 c08cee54 2022-11-08 stsp echo "$nplus new files created:" >&2
110 4ce98cf7 2022-11-08 stsp cat $testroot/repo-list.diff
111 c08cee54 2022-11-08 stsp test_done "$testroot" 1
112 4ce98cf7 2022-11-08 stsp return 1
113 4ce98cf7 2022-11-08 stsp fi
114 c08cee54 2022-11-08 stsp egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.pack' $testroot/repo-list.newlines
115 4ce98cf7 2022-11-08 stsp ret=$?
116 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
117 4ce98cf7 2022-11-08 stsp echo "new pack file not found in ${GOTD_TEST_REPO}"
118 4ce98cf7 2022-11-08 stsp cat $testroot/repo-list.newlines
119 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
120 4ce98cf7 2022-11-08 stsp return 1
121 4ce98cf7 2022-11-08 stsp fi
122 c08cee54 2022-11-08 stsp egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.idx' $testroot/repo-list.newlines
123 4ce98cf7 2022-11-08 stsp ret=$?
124 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
125 4ce98cf7 2022-11-08 stsp echo "new pack index not found in ${GOTD_TEST_REPO}"
126 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
127 4ce98cf7 2022-11-08 stsp return 1
128 4ce98cf7 2022-11-08 stsp fi
129 c08cee54 2022-11-08 stsp fgrep -q '+./refs/heads' $testroot/repo-list.newlines
130 4ce98cf7 2022-11-08 stsp ret=$?
131 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
132 4ce98cf7 2022-11-08 stsp echo "new refs/heads directory not found"
133 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
134 4ce98cf7 2022-11-08 stsp return 1
135 4ce98cf7 2022-11-08 stsp fi
136 c08cee54 2022-11-08 stsp if [ ! -d ${GOTD_TEST_REPO}/refs/heads ]; then
137 4ce98cf7 2022-11-08 stsp echo "new refs/heads is not a directory"
138 c08cee54 2022-11-08 stsp test_done "$testroot" 1
139 4ce98cf7 2022-11-08 stsp return 1
140 4ce98cf7 2022-11-08 stsp fi
141 c08cee54 2022-11-08 stsp fgrep -q '+./refs/heads/master' $testroot/repo-list.newlines
142 4ce98cf7 2022-11-08 stsp ret=$?
143 4ce98cf7 2022-11-08 stsp if [ $ret -ne 0 ]; then
144 4ce98cf7 2022-11-08 stsp echo "new refs/heads/master not found"
145 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
146 4ce98cf7 2022-11-08 stsp return 1
147 4ce98cf7 2022-11-08 stsp fi
148 4ce98cf7 2022-11-08 stsp
149 4ce98cf7 2022-11-08 stsp test_done "$testroot" "$ret"
150 4ce98cf7 2022-11-08 stsp }
151 4ce98cf7 2022-11-08 stsp
152 4ce98cf7 2022-11-08 stsp test_parseargs "$@"
153 4ce98cf7 2022-11-08 stsp run_test test_send_empty