Blame


1 a9c0a12c 2024-04-12 thomas #!/bin/sh
2 a9c0a12c 2024-04-12 thomas #
3 a9c0a12c 2024-04-12 thomas # Copyright (c) 2024 Stefan Sperling <stsp@openbsd.org>
4 a9c0a12c 2024-04-12 thomas #
5 a9c0a12c 2024-04-12 thomas # Permission to use, copy, modify, and distribute this software for any
6 a9c0a12c 2024-04-12 thomas # purpose with or without fee is hereby granted, provided that the above
7 a9c0a12c 2024-04-12 thomas # copyright notice and this permission notice appear in all copies.
8 a9c0a12c 2024-04-12 thomas #
9 a9c0a12c 2024-04-12 thomas # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 a9c0a12c 2024-04-12 thomas # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 a9c0a12c 2024-04-12 thomas # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 a9c0a12c 2024-04-12 thomas # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 a9c0a12c 2024-04-12 thomas # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 a9c0a12c 2024-04-12 thomas # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 a9c0a12c 2024-04-12 thomas # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 a9c0a12c 2024-04-12 thomas
17 a9c0a12c 2024-04-12 thomas . ../cmdline/common.sh
18 a9c0a12c 2024-04-12 thomas . ./common.sh
19 a9c0a12c 2024-04-12 thomas
20 a9c0a12c 2024-04-12 thomas test_send_empty_readonly() {
21 a9c0a12c 2024-04-12 thomas local testroot=`test_init send_empty`
22 a9c0a12c 2024-04-12 thomas local commit_id=`git_show_head $testroot/repo`
23 a9c0a12c 2024-04-12 thomas
24 a9c0a12c 2024-04-12 thomas (cd ${GOTD_TEST_REPO} && find . > $testroot/repo-list.before)
25 a9c0a12c 2024-04-12 thomas
26 a9c0a12c 2024-04-12 thomas # The gotd-controlled test repository starts out empty.
27 a9c0a12c 2024-04-12 thomas got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.before
28 a9c0a12c 2024-04-12 thomas echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
29 a9c0a12c 2024-04-12 thomas cmp -s $testroot/ref-list.expected $testroot/ref-list.before
30 a9c0a12c 2024-04-12 thomas ret=$?
31 a9c0a12c 2024-04-12 thomas if [ $ret -ne 0 ]; then
32 a9c0a12c 2024-04-12 thomas diff -u $testroot/ref-list.expected $testroot/ref-list.before
33 a9c0a12c 2024-04-12 thomas test_done "$testroot" "$ret"
34 a9c0a12c 2024-04-12 thomas return 1
35 a9c0a12c 2024-04-12 thomas fi
36 a9c0a12c 2024-04-12 thomas
37 a9c0a12c 2024-04-12 thomas got checkout -q $testroot/repo $testroot/wt >/dev/null
38 a9c0a12c 2024-04-12 thomas ret=$?
39 a9c0a12c 2024-04-12 thomas if [ $ret -ne 0 ]; then
40 a9c0a12c 2024-04-12 thomas echo "got checkout failed unexpectedly" >&2
41 a9c0a12c 2024-04-12 thomas test_done "$testroot" 1
42 a9c0a12c 2024-04-12 thomas return 1
43 a9c0a12c 2024-04-12 thomas fi
44 a9c0a12c 2024-04-12 thomas
45 a9c0a12c 2024-04-12 thomas # send contents of $testroot/repo to ${GOTD_TEST_REPO}
46 a9c0a12c 2024-04-12 thomas cat >> $testroot/wt/.got/got.conf <<EOF
47 a9c0a12c 2024-04-12 thomas remote "gotd" {
48 a9c0a12c 2024-04-12 thomas server ${GOTD_DEVUSER}@127.0.0.1
49 a9c0a12c 2024-04-12 thomas repository "test-repo"
50 a9c0a12c 2024-04-12 thomas protocol ssh
51 a9c0a12c 2024-04-12 thomas }
52 a9c0a12c 2024-04-12 thomas EOF
53 a9c0a12c 2024-04-12 thomas (cd $testroot/wt && got send -q -a gotd 2> $testroot/stderr)
54 a9c0a12c 2024-04-12 thomas ret=$?
55 a9c0a12c 2024-04-12 thomas if [ $ret -eq 0 ]; then
56 a9c0a12c 2024-04-12 thomas echo "got send succeeded unexpectedly" >&2
57 a9c0a12c 2024-04-12 thomas test_done "$testroot" 1
58 a9c0a12c 2024-04-12 thomas return 1
59 a9c0a12c 2024-04-12 thomas fi
60 a9c0a12c 2024-04-12 thomas
61 a9c0a12c 2024-04-12 thomas echo "got-send-pack: test-repo: Permission denied" \
62 a9c0a12c 2024-04-12 thomas > $testroot/stderr.expected
63 a9c0a12c 2024-04-12 thomas grep '^got-send-pack:' $testroot/stderr > $testroot/stderr.filtered
64 a9c0a12c 2024-04-12 thomas cmp -s $testroot/stderr.expected $testroot/stderr.filtered
65 a9c0a12c 2024-04-12 thomas ret=$?
66 a9c0a12c 2024-04-12 thomas if [ $ret -ne 0 ]; then
67 a9c0a12c 2024-04-12 thomas diff -u $testroot/stderr.expected $testroot/stderr.filtered
68 a9c0a12c 2024-04-12 thomas test_done "$testroot" "$ret"
69 a9c0a12c 2024-04-12 thomas return 1
70 a9c0a12c 2024-04-12 thomas fi
71 a9c0a12c 2024-04-12 thomas
72 a9c0a12c 2024-04-12 thomas # Server should not have created a new reference.
73 a9c0a12c 2024-04-12 thomas got ref -l -r ${GOTD_TEST_REPO} > $testroot/ref-list.after
74 a9c0a12c 2024-04-12 thomas echo "HEAD: refs/heads/main" > $testroot/ref-list.expected
75 a9c0a12c 2024-04-12 thomas cmp -s $testroot/ref-list.expected $testroot/ref-list.after
76 a9c0a12c 2024-04-12 thomas ret=$?
77 a9c0a12c 2024-04-12 thomas if [ $ret -ne 0 ]; then
78 a9c0a12c 2024-04-12 thomas diff -u $testroot/ref-list.expected $testroot/ref-list.after
79 a9c0a12c 2024-04-12 thomas test_done "$testroot" "$ret"
80 a9c0a12c 2024-04-12 thomas return 1
81 a9c0a12c 2024-04-12 thomas fi
82 a9c0a12c 2024-04-12 thomas
83 a9c0a12c 2024-04-12 thomas test_done "$testroot" "$ret"
84 a9c0a12c 2024-04-12 thomas }
85 a9c0a12c 2024-04-12 thomas
86 a9c0a12c 2024-04-12 thomas test_parseargs "$@"
87 a9c0a12c 2024-04-12 thomas run_test test_send_empty_readonly