Skip to content

Commit 8f788eb

Browse files
avargitster
authored andcommitted
t: create test harness for 'bundle-uri' command
The previous change allowed for a Git server to advertise the 'bundle-uri' command as a capability based on the uploadPack.advertiseBundleURIs config option. Create a set of tests that check that this capability is advertised using 'git ls-remote'. In order to test this functionality across three protocols (file, git, and http), create lib-bundle-uri-protocol.sh to generalize the tests, allowing the other test scripts to set an environment variable and otherwise inherit the setup and tests from this script. The tests currently only test that the 'bundle-uri' command is advertised or not. Other actions will be tested as the Git client learns to request the 'bundle-uri' command and parse its response. To help with URI escaping, specifically for file paths with a space in them, extract a 'sed' invocation from t9199-git-svn-info.sh into a helper function for use here, too. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8b8d9a2 commit 8f788eb

6 files changed

+144
-1
lines changed

t/lib-bundle-uri-protocol.sh

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Set up and run tests of the 'bundle-uri' command in protocol v2
2+
#
3+
# The test that includes this script should set BUNDLE_URI_PROTOCOL
4+
# to one of "file", "git", or "http".
5+
6+
BUNDLE_URI_TEST_PARENT=
7+
BUNDLE_URI_TEST_URI=
8+
BUNDLE_URI_TEST_BUNDLE_URI=
9+
case "$BUNDLE_URI_PROTOCOL" in
10+
file)
11+
BUNDLE_URI_PARENT=file_parent
12+
BUNDLE_URI_REPO_URI="file://$PWD/file_parent"
13+
BUNDLE_URI_BUNDLE_URI="$BUNDLE_URI_REPO_URI/fake.bdl"
14+
test_set_prereq BUNDLE_URI_FILE
15+
;;
16+
git)
17+
. "$TEST_DIRECTORY"/lib-git-daemon.sh
18+
start_git_daemon --export-all --enable=receive-pack
19+
BUNDLE_URI_PARENT="$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent"
20+
BUNDLE_URI_REPO_URI="$GIT_DAEMON_URL/parent"
21+
BUNDLE_URI_BUNDLE_URI="https://example.com/fake.bdl"
22+
test_set_prereq BUNDLE_URI_GIT
23+
;;
24+
http)
25+
. "$TEST_DIRECTORY"/lib-httpd.sh
26+
start_httpd
27+
BUNDLE_URI_PARENT="$HTTPD_DOCUMENT_ROOT_PATH/http_parent"
28+
BUNDLE_URI_REPO_URI="$HTTPD_URL/smart/http_parent"
29+
BUNDLE_URI_BUNDLE_URI="https://example.com/fake.bdl"
30+
test_set_prereq BUNDLE_URI_HTTP
31+
;;
32+
*)
33+
BUG "Need to pass valid BUNDLE_URI_PROTOCOL (was \"$BUNDLE_URI_PROTOCOL\")"
34+
;;
35+
esac
36+
37+
test_expect_success "setup protocol v2 $BUNDLE_URI_PROTOCOL:// tests" '
38+
git init "$BUNDLE_URI_PARENT" &&
39+
test_commit -C "$BUNDLE_URI_PARENT" one &&
40+
git -C "$BUNDLE_URI_PARENT" config uploadpack.advertiseBundleURIs true
41+
'
42+
43+
case "$BUNDLE_URI_PROTOCOL" in
44+
http)
45+
test_expect_success "setup config for $BUNDLE_URI_PROTOCOL:// tests" '
46+
git -C "$BUNDLE_URI_PARENT" config http.receivepack true
47+
'
48+
;;
49+
*)
50+
;;
51+
esac
52+
BUNDLE_URI_BUNDLE_URI_ESCAPED=$(echo "$BUNDLE_URI_BUNDLE_URI" | test_uri_escape)
53+
54+
test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: no bundle-uri" '
55+
test_when_finished "rm -f log" &&
56+
test_when_finished "git -C \"$BUNDLE_URI_PARENT\" config uploadpack.advertiseBundleURIs true" &&
57+
git -C "$BUNDLE_URI_PARENT" config uploadpack.advertiseBundleURIs false &&
58+
59+
GIT_TRACE_PACKET="$PWD/log" \
60+
git \
61+
-c protocol.version=2 \
62+
ls-remote --symref "$BUNDLE_URI_REPO_URI" \
63+
>actual 2>err &&
64+
65+
# Server responded using protocol v2
66+
grep "< version 2" log &&
67+
68+
! grep bundle-uri log
69+
'
70+
71+
test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: have bundle-uri" '
72+
test_when_finished "rm -f log" &&
73+
74+
GIT_TRACE_PACKET="$PWD/log" \
75+
git \
76+
-c protocol.version=2 \
77+
ls-remote --symref "$BUNDLE_URI_REPO_URI" \
78+
>actual 2>err &&
79+
80+
# Server responded using protocol v2
81+
grep "< version 2" log &&
82+
83+
# Server advertised bundle-uri capability
84+
grep "< bundle-uri" log
85+
'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
test_description="Test bundle-uri with protocol v2 and 'file://' transport"
4+
5+
TEST_NO_CREATE_REPO=1
6+
7+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9+
10+
. ./test-lib.sh
11+
12+
# Test protocol v2 with 'file://' transport
13+
#
14+
BUNDLE_URI_PROTOCOL=file
15+
. "$TEST_DIRECTORY"/lib-bundle-uri-protocol.sh
16+
17+
test_done

t/t5731-protocol-v2-bundle-uri-git.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
test_description="Test bundle-uri with protocol v2 and 'git://' transport"
4+
5+
TEST_NO_CREATE_REPO=1
6+
7+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9+
10+
. ./test-lib.sh
11+
12+
# Test protocol v2 with 'git://' transport
13+
#
14+
BUNDLE_URI_PROTOCOL=git
15+
. "$TEST_DIRECTORY"/lib-bundle-uri-protocol.sh
16+
17+
test_done
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
test_description="Test bundle-uri with protocol v2 and 'http://' transport"
4+
5+
TEST_NO_CREATE_REPO=1
6+
7+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9+
10+
. ./test-lib.sh
11+
12+
# Test protocol v2 with 'http://' transport
13+
#
14+
BUNDLE_URI_PROTOCOL=http
15+
. "$TEST_DIRECTORY"/lib-bundle-uri-protocol.sh
16+
17+
test_done

t/t9119-git-svn-info.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test_cmp_info () {
2828
rm -f tmp.expect tmp.actual
2929
}
3030

31-
quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')"
31+
quoted_svnrepo="$(echo $svnrepo | test_uri_escape)"
3232

3333
test_expect_success 'setup repository and import' '
3434
mkdir info &&

t/test-lib-functions.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,13 @@ test_path_is_hidden () {
17511751
return 1
17521752
}
17531753

1754+
# Poor man's URI escaping. Good enough for the test suite whose trash
1755+
# directory has a space in it. See 93c3fcbe4d4 (git-svn: attempt to
1756+
# mimic SVN 1.7 URL canonicalization, 2012-07-28) for prior art.
1757+
test_uri_escape() {
1758+
sed 's/ /%20/g'
1759+
}
1760+
17541761
# Check that the given command was invoked as part of the
17551762
# trace2-format trace on stdin.
17561763
#

0 commit comments

Comments
 (0)