Blame


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