Blame


1 f2900386 2022-10-31 thomas #!/bin/sh
2 f2900386 2022-10-31 thomas #
3 f2900386 2022-10-31 thomas # Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 f2900386 2022-10-31 thomas #
5 f2900386 2022-10-31 thomas # Permission to use, copy, modify, and distribute this software for any
6 f2900386 2022-10-31 thomas # purpose with or without fee is hereby granted, provided that the above
7 f2900386 2022-10-31 thomas # copyright notice and this permission notice appear in all copies.
8 f2900386 2022-10-31 thomas #
9 f2900386 2022-10-31 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 f2900386 2022-10-31 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 f2900386 2022-10-31 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 f2900386 2022-10-31 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 f2900386 2022-10-31 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 f2900386 2022-10-31 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 f2900386 2022-10-31 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 f2900386 2022-10-31 thomas
17 f2900386 2022-10-31 thomas . ../cmdline/common.sh
18 f2900386 2022-10-31 thomas . ./common.sh
19 f2900386 2022-10-31 thomas
20 f2900386 2022-10-31 thomas test_send_basic() {
21 f2900386 2022-10-31 thomas local testroot=`test_init send_basic 1`
22 f2900386 2022-10-31 thomas
23 f2900386 2022-10-31 thomas ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.before
24 f2900386 2022-10-31 thomas
25 f2900386 2022-10-31 thomas got clone -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone
26 f2900386 2022-10-31 thomas ret=$?
27 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
28 f2900386 2022-10-31 thomas echo "got clone failed unexpectedly" >&2
29 f2900386 2022-10-31 thomas test_done "$testroot" "1"
30 f2900386 2022-10-31 thomas return 1
31 f2900386 2022-10-31 thomas fi
32 f2900386 2022-10-31 thomas
33 c9aa63fb 2023-01-10 thomas # create a second clone to test an incremental fetch with later
34 c9aa63fb 2023-01-10 thomas got clone -q -m ${GOTD_TEST_REPO_URL} $testroot/repo-clone2
35 c9aa63fb 2023-01-10 thomas ret=$?
36 c9aa63fb 2023-01-10 thomas if [ $ret -ne 0 ]; then
37 c9aa63fb 2023-01-10 thomas echo "got clone failed unexpectedly" >&2
38 c9aa63fb 2023-01-10 thomas test_done "$testroot" "1"
39 c9aa63fb 2023-01-10 thomas return 1
40 c9aa63fb 2023-01-10 thomas fi
41 c9aa63fb 2023-01-10 thomas
42 f2900386 2022-10-31 thomas got checkout -q $testroot/repo-clone $testroot/wt >/dev/null
43 f2900386 2022-10-31 thomas ret=$?
44 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
45 f2900386 2022-10-31 thomas echo "got checkout failed unexpectedly" >&2
46 f2900386 2022-10-31 thomas test_done "$testroot" "1"
47 f2900386 2022-10-31 thomas return 1
48 f2900386 2022-10-31 thomas fi
49 f2900386 2022-10-31 thomas
50 f2900386 2022-10-31 thomas mkdir $testroot/wt/psi
51 f2900386 2022-10-31 thomas echo "new" > $testroot/wt/psi/new
52 f2900386 2022-10-31 thomas (cd $testroot/wt && got add psi/new > /dev/null)
53 f2900386 2022-10-31 thomas echo "more alpha" >> $testroot/wt/alpha
54 f2900386 2022-10-31 thomas (cd $testroot/wt && got commit -m 'make changes' > /dev/null)
55 f2900386 2022-10-31 thomas
56 f2900386 2022-10-31 thomas got send -q -r $testroot/repo-clone
57 f2900386 2022-10-31 thomas ret=$?
58 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
59 f2900386 2022-10-31 thomas echo "got send failed unexpectedly" >&2
60 f2900386 2022-10-31 thomas test_done "$testroot" "1"
61 f2900386 2022-10-31 thomas return 1
62 f2900386 2022-10-31 thomas fi
63 f2900386 2022-10-31 thomas
64 f2900386 2022-10-31 thomas # Verify that the send operation worked fine.
65 c9aa63fb 2023-01-10 thomas got fetch -q -r $testroot/repo-clone2
66 f2900386 2022-10-31 thomas ret=$?
67 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
68 c9aa63fb 2023-01-10 thomas echo "got fetch failed unexpectedly" >&2
69 f2900386 2022-10-31 thomas test_done "$testroot" "1"
70 f2900386 2022-10-31 thomas return 1
71 f2900386 2022-10-31 thomas fi
72 f2900386 2022-10-31 thomas
73 f2900386 2022-10-31 thomas got tree -R -r $testroot/repo-clone2 > $testroot/stdout
74 f2900386 2022-10-31 thomas cat > $testroot/stdout.expected <<EOF
75 f2900386 2022-10-31 thomas alpha
76 f2900386 2022-10-31 thomas beta
77 f2900386 2022-10-31 thomas epsilon/
78 f2900386 2022-10-31 thomas epsilon/zeta
79 f2900386 2022-10-31 thomas gamma/
80 f2900386 2022-10-31 thomas gamma/delta
81 f2900386 2022-10-31 thomas psi/
82 f2900386 2022-10-31 thomas psi/new
83 f2900386 2022-10-31 thomas EOF
84 f2900386 2022-10-31 thomas cmp -s $testroot/stdout.expected $testroot/stdout
85 f2900386 2022-10-31 thomas ret=$?
86 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
87 f2900386 2022-10-31 thomas diff -u $testroot/stdout.expected $testroot/stdout
88 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
89 f2900386 2022-10-31 thomas return 1
90 f2900386 2022-10-31 thomas fi
91 f2900386 2022-10-31 thomas
92 f2900386 2022-10-31 thomas # sending to a repository should result in a new pack file
93 f2900386 2022-10-31 thomas ls -R ${GOTD_TEST_REPO} > $testroot/repo-list.after
94 f2900386 2022-10-31 thomas diff -u $testroot/repo-list.before $testroot/repo-list.after \
95 f2900386 2022-10-31 thomas > $testroot/repo-list.diff
96 f2900386 2022-10-31 thomas grep '^+[^+]' < $testroot/repo-list.diff > $testroot/repo-list.newlines
97 f2900386 2022-10-31 thomas nplus=`wc -l < $testroot/repo-list.newlines | tr -d ' '`
98 f2900386 2022-10-31 thomas if [ "$nplus" != "2" ]; then
99 f2900386 2022-10-31 thomas echo "$nplus new files created"
100 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
101 f2900386 2022-10-31 thomas return 1
102 f2900386 2022-10-31 thomas fi
103 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.pack' $testroot/repo-list.newlines
104 f2900386 2022-10-31 thomas ret=$?
105 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
106 f2900386 2022-10-31 thomas echo "new pack file not found in ${GOTD_TEST_REPO}"
107 f2900386 2022-10-31 thomas cat $testroot/repo-list.newlines
108 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
109 f2900386 2022-10-31 thomas return 1
110 f2900386 2022-10-31 thomas fi
111 f2900386 2022-10-31 thomas egrep -q '\+pack-[a-f0-9]{40}.idx' $testroot/repo-list.newlines
112 f2900386 2022-10-31 thomas ret=$?
113 f2900386 2022-10-31 thomas if [ $ret -ne 0 ]; then
114 f2900386 2022-10-31 thomas echo "new pack index not found in ${GOTD_TEST_REPO}"
115 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
116 f2900386 2022-10-31 thomas return 1
117 f2900386 2022-10-31 thomas fi
118 f2900386 2022-10-31 thomas
119 f2900386 2022-10-31 thomas test_done "$testroot" "$ret"
120 f2900386 2022-10-31 thomas }
121 f2900386 2022-10-31 thomas
122 f2900386 2022-10-31 thomas test_parseargs "$@"
123 f2900386 2022-10-31 thomas run_test test_send_basic