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