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