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_basic() {
21 local testroot=`test_init send_basic 1`
23 ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.before
25 got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 ret=$?
27 if [ $ret -ne 0 ]; then
28 echo "got clone failed unexpectedly" >&2
29 test_done "$testroot" "1"
30 return 1
31 fi
33 # create a second clone to test an incremental fetch with later
34 got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
35 ret=$?
36 if [ $ret -ne 0 ]; then
37 echo "got clone failed unexpectedly" >&2
38 test_done "$testroot" "1"
39 return 1
40 fi
42 got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
43 ret=$?
44 if [ $ret -ne 0 ]; then
45 echo "got checkout failed unexpectedly" >&2
46 test_done "$testroot" "1"
47 return 1
48 fi
50 mkdir $testroot/wt/psi
51 echo "new" > $testroot/wt/psi/new
52 (cd $testroot/wt && got add psi/new > /dev/null)
53 echo "more alpha" >> $testroot/wt/alpha
54 (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
56 got send -q -r $testroot/repo-clone
57 ret=$?
58 if [ $ret -ne 0 ]; then
59 echo "got send failed unexpectedly" >&2
60 test_done "$testroot" "1"
61 return 1
62 fi
64 # Verify that the send operation worked fine.
65 got fetch -q -r $testroot/repo-clone2
66 ret=$?
67 if [ $ret -ne 0 ]; then
68 echo "got fetch failed unexpectedly" >&2
69 test_done "$testroot" "1"
70 return 1
71 fi
73 got tree -R -r $testroot/repo-clone2 > $testroot/stdout
74 cat > $testroot/stdout.expected <<EOF
75 alpha
76 beta
77 epsilon/
78 epsilon/zeta
79 gamma/
80 gamma/delta
81 psi/
82 psi/new
83 EOF
84 cmp -s $testroot/stdout.expected $testroot/stdout
85 ret=$?
86 if [ $ret -ne 0 ]; then
87 diff -u $testroot/stdout.expected $testroot/stdout
88 test_done "$testroot" "$ret"
89 return 1
90 fi
92 # sending to a repository should result in a new pack file
93 ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.after
94 diff -u $testroot/repo-list.before $testroot/repo-list.after \
95 > $testroot/repo-list.diff
96 grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
97 nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
98 if [ "$nplus" != "2" ]; then
99 echo "$nplus new files created"
100 test_done "$testroot" "$ret"
101 return 1
102 fi
103 egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
104 ret=$?
105 if [ $ret -ne 0 ]; then
106 echo "new pack file not found in ${GOTD_TEST_REPO}"
107 cat $testroot/repo-list.newlines
108 test_done "$testroot" "$ret"
109 return 1
110 fi
111 egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
112 ret=$?
113 if [ $ret -ne 0 ]; then
114 echo "new pack index not found in ${GOTD_TEST_REPO}"
115 test_done "$testroot" "$ret"
116 return 1
117 fi
119 test_done "$testroot" "$ret"
122 test_parseargs "$@"
123 run_test test_send_basic