t5551: handle v2 protocol when checking curl trace

After cloning an http repository, we check the curl trace to make sure the expected requests were made. But since the expected trace was never updated to handle v2, it is only run when you ask the test suite to run in v0 mode (which hardly anybody does). Let's update it to handle both protocols. This isn't too hard since v2 just sends an extra header and an extra request. So we can just annotate those extra lines and strip them out for v0 (and drop the annotations for v2). I didn't bother handling v1 here, as it's not really of practical interest (it would drop the extra v2 request, but still have the "git-protocol" lines). There's a similar tweak needed at the end. Since we check the "accept-encoding" value loosely, we grep for it rather than finding it in the verbatim trace. This grep insists that there are exactly 2 matches, but of course in v2 with the extra request there are 3. We could tweak the number, but it's simpler still to just check that we saw at least one match. The verbatim check already confirmed how many instances of the header we have; we're really just checking here that "gzip" is in the value (it's possible, of course, that the headers could have different values, but that seems like an unlikely bug). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 23, 2023 at 05:59 UTC 1c5a63818a4a421753b33d12fabcd316c229e61a
1 file changed +25 -11
t/t5551-http-fetch-smart.sh
+25 -11
@@ -33,12 +33,13 @@ test_expect_success 'create http-accessible bare repository' '
33 setup_askpass_helper
34
35 test_expect_success 'clone http repository' '
36 - cat >exp <<-EOF &&
36 + cat >exp.raw <<-EOF &&
37 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
38 > accept: */*
39 > accept-encoding: ENCODINGS
40 > accept-language: ko-KR, *;q=0.9
41 > pragma: no-cache
42 + {V2} > git-protocol: version=2
43 < $HTTP_PROTO 200 OK
44 < pragma: no-cache
45 < cache-control: no-cache, max-age=0, must-revalidate
@@ -48,13 +49,32 @@ test_expect_success 'clone http repository' '
49 > content-type: application/x-git-upload-pack-request
50 > accept: application/x-git-upload-pack-result
51 > accept-language: ko-KR, *;q=0.9
52 + {V2} > git-protocol: version=2
53 > content-length: xxx
54 < HTTP/1.1 200 OK
55 < pragma: no-cache
56 < cache-control: no-cache, max-age=0, must-revalidate
57 < content-type: application/x-git-upload-pack-result
58 + {V2} > POST /smart/repo.git/git-upload-pack HTTP/1.1
59 + {V2} > accept-encoding: ENCODINGS
60 + {V2} > content-type: application/x-git-upload-pack-request
61 + {V2} > accept: application/x-git-upload-pack-result
62 + {V2} > accept-language: ko-KR, *;q=0.9
63 + {V2} > git-protocol: version=2
64 + {V2} > content-length: xxx
65 + {V2} < HTTP/1.1 200 OK
66 + {V2} < pragma: no-cache
67 + {V2} < cache-control: no-cache, max-age=0, must-revalidate
68 + {V2} < content-type: application/x-git-upload-pack-result
69 EOF
70
71 + if test "$GIT_TEST_PROTOCOL_VERSION" = 0
72 + then
73 + sed "/^{V2}/d" <exp.raw >exp
74 + else
75 + sed "s/^{V2} //" <exp.raw >exp
76 + fi &&
77 +
78 GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" \
79 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
80 test_cmp file clone/file &&
@@ -107,17 +127,11 @@ test_expect_success 'clone http repository' '
127 /^< transfer-encoding: /d
128 " >actual &&
129
110 - # NEEDSWORK: If the overspecification of the expected result is reduced, we
111 - # might be able to run this test in all protocol versions.
112 - if test "$GIT_TEST_PROTOCOL_VERSION" = 0
113 - then
114 - sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
115 - actual >actual.smudged &&
116 - test_cmp exp actual.smudged &&
130 + sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
131 + actual >actual.smudged &&
132 + test_cmp exp actual.smudged &&
133
118 - grep "accept-encoding:.*gzip" actual >actual.gzip &&
119 - test_line_count = 2 actual.gzip
120 - fi
134 + grep "accept-encoding:.*gzip" actual >actual.gzip
135 '
136
137 test_expect_success 'fetch changes via http' '