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