Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2022 Stefan Sperling <stsp@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 test_send_empty() {
21 local testroot=`test_init send_empty`
22 local commit_id=`git_show_head $testroot/repo`
24 (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
26 # The gotd-controlled test repository starts out empty.
27 got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 ret=$?
31 if [ $ret -ne 0 ]; then
32 diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 test_done "$testroot" "$ret"
34 return 1
35 fi
37 got checkout -q $testroot/repo $testroot/wt >/dev/null
38 ret=$?
39 if [ $ret -ne 0 ]; then
40 echo "got checkout failed unexpectedly" >&2
41 test_done "$testroot" 1
42 return 1
43 fi
45 # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 cat >> $testroot/wt/.got/got.conf <<EOF
47 remote "gotd" {
48 server ${GOTD_DEVUSER}@127.0.0.1
49 repository "test-repo"
50 protocol ssh
51 }
52 EOF
53 (cd $testroot/wt && got send -q -a gotd)
54 ret=$?
55 if [ $ret -ne 0 ]; then
56 echo "got send failed unexpectedly" >&2
57 test_done "$testroot" 1
58 return 1
59 fi
61 # Server should have created a new reference.
62 got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
63 cat > $testroot/ref-list.expected <<EOF
64 HEAD: refs/heads/main
65 refs/heads/master: $commit_id
66 EOF
67 cmp -s $testroot/ref-list.expected $testroot/ref-list.after
68 ret=$?
69 if [ $ret -ne 0 ]; then
70 diff -u $testroot/ref-list.expected $testroot/ref-list.after
71 test_done "$testroot" "$ret"
72 return 1
73 fi
75 # Verify that the result can be cloned again.
76 # XXX need -b master at present because gotd does not rewrite HEAD
77 got clone -q -b master ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
78 ret=$?
79 if [ $ret -ne 0 ]; then
80 echo "got clone failed unexpectedly" >&2
81 test_done "$testroot" 1
82 return 1
83 fi
85 got tree -R -r $testroot/repo-clone2 > $testroot/stdout
86 cat > $testroot/stdout.expected <<EOF
87 alpha
88 beta
89 epsilon/
90 epsilon/zeta
91 gamma/
92 gamma/delta
93 EOF
94 cmp -s $testroot/stdout.expected $testroot/stdout
95 ret=$?
96 if [ $ret -ne 0 ]; then
97 diff -u $testroot/stdout.expected $testroot/stdout
98 test_done "$testroot" "$ret"
99 return 1
100 fi
102 # sending to a repository should result in a new pack file
103 (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.after)
104 diff -u $testroot/repo-list.before $testroot/repo-list.after \
105 > $testroot/repo-list.diff
106 grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
107 nplus=`awk '/^\+[^+]/{c++} END{print c}' $testroot/repo-list.diff`
108 if [ "$nplus" != "4" ]; then
109 echo "$nplus new files created:" >&2
110 cat $testroot/repo-list.diff
111 test_done "$testroot" 1
112 return 1
113 fi
114 egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.pack' $testroot/repo-list.newlines
115 ret=$?
116 if [ $ret -ne 0 ]; then
117 echo "new pack file not found in ${GOTD_TEST_REPO}"
118 cat $testroot/repo-list.newlines
119 test_done "$testroot" "$ret"
120 return 1
121 fi
122 egrep -q '\+\./objects/pack/pack-[a-f0-9]{40}\.idx' $testroot/repo-list.newlines
123 ret=$?
124 if [ $ret -ne 0 ]; then
125 echo "new pack index not found in ${GOTD_TEST_REPO}"
126 test_done "$testroot" "$ret"
127 return 1
128 fi
129 fgrep -q '+./refs/heads' $testroot/repo-list.newlines
130 ret=$?
131 if [ $ret -ne 0 ]; then
132 echo "new refs/heads directory not found"
133 test_done "$testroot" "$ret"
134 return 1
135 fi
136 if [ ! -d ${GOTD_TEST_REPO}/refs/heads ]; then
137 echo "new refs/heads is not a directory"
138 test_done "$testroot" 1
139 return 1
140 fi
141 fgrep -q '+./refs/heads/master' $testroot/repo-list.newlines
142 ret=$?
143 if [ $ret -ne 0 ]; then
144 echo "new refs/heads/master not found"
145 test_done "$testroot" "$ret"
146 return 1
147 fi
149 test_done "$testroot" "$ret"
152 test_parseargs "$@"
153 run_test test_send_empty