From: Ivan Todoroski <grnch@gmx.net>
To: Jeff King <peff@peff.net>
Cc: Shawn Pearce <spearce@spearce.org>,
Nguyen Thai Ngoc Duy <pclouds@gmail.com>,
Jakub Narebski <jnareb@gmail.com>,
git@vger.kernel.org
Subject: [PATCH/RFC v2 3/4] fetch-pack: test cases for the new --stdin option
Date: Tue, 27 Mar 2012 08:27:11 +0200 [thread overview]
Message-ID: <4F715DBF.6030909@gmx.net> (raw)
In-Reply-To: <4F715CF7.5070903@gmx.net>
These test cases focus only on testing the parsing of refs on stdin,
without bothering with the rest of the fetch-pack machinery. We pass in
the refs using different combinations of command line and stdin and then
we watch fetch-pack's stdout to see whether it prints all the refs we
specified and in the same order as we specified them.
For the --stateless-rpc tests we cannot easily execute fetch-pack to the
end because that would require simulating the remote protocol. We settle
for only checking 2 cases:
1) Whether fetch-pack correctly fails to parse the refs if they are not
terminated by a flush packet
2) Whether fetch-pack finishes parsing the refs without error when they
are correctly terminated by a flush packet
The fetch-pack invocation fails in both cases due to the missing remote
side of the protocol, but it fails in different ways which allows us to
determine how the refs parsing ended by inspecting the different error
messages.
---
t/t5500-fetch-pack.sh | 100 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 100 insertions(+)
diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh
index 9bf69e9a0f..f4de7d07c1 100755
--- a/t/t5500-fetch-pack.sh
+++ b/t/t5500-fetch-pack.sh
@@ -248,4 +248,104 @@ test_expect_success 'clone shallow object count' '
grep "^count: 52" count.shallow
'
+
+cat >stdin.exp <<EOF
+refs/heads/C
+refs/heads/A
+refs/heads/D
+refs/tags/C
+refs/heads/B
+refs/tags/A
+refs/heads/E
+refs/tags/B
+refs/tags/E
+refs/tags/D
+EOF
+
+test_expect_success 'setup tests for --stdin' '
+ for head in C D E F; do
+ add $head
+ done &&
+ for head in A B C D E F; do
+ git tag $head $head
+ done
+'
+
+test_expect_success 'fetch refs from cmdline, make sure it still works OK' '
+ cd client &&
+ git fetch-pack --no-progress .. $(cat ../stdin.exp) |
+ cut -d " " -f 2 > ../stdin.act &&
+ cd .. &&
+ test_cmp stdin.exp stdin.act
+'
+
+test_expect_success 'fetch refs from stdin' '
+ cd client &&
+ cat ../stdin.exp |
+ git fetch-pack --stdin --no-progress .. |
+ cut -d " " -f 2 > ../stdin.act &&
+ cd .. &&
+ test_cmp stdin.exp stdin.act
+'
+
+test_expect_success 'fetch mixed refs from cmdline and stdin in right order' '
+ cd client &&
+ tail -n +5 ../stdin.exp |
+ git fetch-pack --stdin --no-progress .. $(head -n 4 ../stdin.exp) |
+ cut -d " " -f 2 > ../stdin.act &&
+ cd .. &&
+ test_cmp stdin.exp stdin.act
+'
+
+
+# remove final newline and insert random spaces, NULs, and empty lines
+head -c -1 stdin.exp | sed -e '
+ 1i
+ 2s/^\|$/ /g
+ 4s/^/ /
+ 6s/$/ /
+ 8s/$/\n /
+ 9s/$/Ztrailing garbage/
+ 9s/^\|$/ /g
+' | tr "Z" "\000" > stdin.spaces
+
+test_expect_success 'ignore leading/trailing spaces, empty lines and NULs' '
+ cd client &&
+ cat ../stdin.spaces |
+ git fetch-pack --stdin --no-progress .. |
+ cut -d " " -f 2 > ../stdin.act &&
+ cd .. &&
+ test_cmp stdin.exp stdin.act
+'
+
+
+packet_write() { printf "%04x%s\n" $((${#1} + 5)) "$1"; }
+packet_flush() { printf "0000"; }
+
+cat stdin.exp | while read ref; do
+ packet_write $ref
+done | tee stdin.pkt.bad |
+(packet_flush; packet_write garbage) > stdin.pkt.good
+
+echo "fatal: protocol error: expected sha/ref, got 'garbage'" > stdin.pkt.good.exp
+echo "fatal: The remote end hung up unexpectedly" > stdin.pkt.bad.exp
+
+test_expect_success 'refs on stdin in packetized format' '
+ cd client &&
+ cat ../stdin.pkt.good |
+ test_must_fail git fetch-pack --stdin --stateless-rpc .. \
+ 2> ../stdin.pkt.good.act &&
+ cd .. &&
+ test_cmp stdin.pkt.good.exp stdin.pkt.good.act
+'
+
+test_expect_success 'fail if flush packet is missing' '
+ cd client &&
+ cat ../stdin.pkt.bad |
+ test_must_fail git fetch-pack --stdin --stateless-rpc .. \
+ 2> ../stdin.pkt.bad.act &&
+ cd .. &&
+ test_cmp stdin.pkt.bad.exp stdin.pkt.bad.act
+'
+
test_done
--
1.7.9.5.4.g4f508
next prev parent reply other threads:[~2012-03-27 6:26 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-18 8:14 Clone fails on a repo with too many heads/tags Ivan Todoroski
2012-03-18 11:37 ` Ivan Todoroski
2012-03-18 12:04 ` Nguyen Thai Ngoc Duy
2012-03-18 16:36 ` Jakub Narebski
2012-03-18 19:07 ` Jeff King
2012-03-18 22:07 ` Jakub Narebski
2012-03-19 2:32 ` Jeff King
2012-03-19 2:43 ` Nguyen Thai Ngoc Duy
2012-03-19 2:45 ` Jeff King
2012-03-19 1:05 ` Ivan Todoroski
2012-03-19 1:30 ` Nguyen Thai Ngoc Duy
2012-03-19 2:44 ` Jeff King
2012-03-21 11:05 ` Ivan Todoroski
2012-03-21 14:28 ` Shawn Pearce
2012-03-21 17:14 ` Jeff King
2012-03-21 17:59 ` Jakub Narebski
2012-03-21 20:02 ` Ivan Todoroski
2012-03-21 20:17 ` Jeff King
2012-03-24 20:49 ` Ivan Todoroski
2012-03-25 1:06 ` Jeff King
2012-03-25 2:32 ` Jeff King
2012-03-25 17:33 ` Ivan Todoroski
2012-03-25 17:54 ` Ivan Todoroski
2012-03-26 17:33 ` Jeff King
2012-03-27 7:07 ` Ivan Todoroski
2012-03-25 15:30 ` Ivan Todoroski
2012-03-24 20:53 ` [PATCH/RFC 1/2] fetch-pack: new option to read refs from stdin Ivan Todoroski
2012-03-25 1:19 ` Jeff King
2012-03-25 9:39 ` Ivan Todoroski
2012-03-25 15:15 ` Ivan Todoroski
2012-03-25 20:00 ` Ivan Todoroski
2012-03-26 17:21 ` Jeff King
2012-03-26 17:49 ` Ivan Todoroski
2012-03-26 17:51 ` Jeff King
2012-03-24 20:54 ` [PATCH/RFC 2/2] remote-curl: send the refs to fetch-pack on stdin Ivan Todoroski
2012-03-25 1:24 ` Jeff King
2012-03-25 9:52 ` Ivan Todoroski
2012-03-26 17:24 ` Jeff King
2012-03-27 6:23 ` [PATCH/RFC v2 0/4] Fix fetch-pack command line overflow during clone Ivan Todoroski
2012-03-27 6:25 ` [PATCH/RFC v2 1/4] fetch-pack: new --stdin option to read refs from stdin Ivan Todoroski
2012-03-27 16:59 ` Junio C Hamano
2012-03-27 23:18 ` Ivan Todoroski
2012-03-27 23:26 ` Junio C Hamano
2012-03-27 23:48 ` Ivan Todoroski
2012-03-27 6:26 ` [PATCH/RFC v2 2/4] remote-curl: send the refs to fetch-pack on stdin Ivan Todoroski
2012-03-27 17:18 ` Junio C Hamano
2012-03-27 23:20 ` Ivan Todoroski
2012-03-27 6:27 ` Ivan Todoroski [this message]
2012-03-27 17:40 ` [PATCH/RFC v2 3/4] fetch-pack: test cases for the new --stdin option Junio C Hamano
2012-03-27 23:36 ` Ivan Todoroski
2012-03-27 23:43 ` Junio C Hamano
2012-03-28 0:14 ` Ivan Todoroski
2012-03-27 6:28 ` [PATCH/RFC v2 4/4] remote-curl: main test case for the OS command line overflow Ivan Todoroski
2012-03-27 17:43 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4F715DBF.6030909@gmx.net \
--to=grnch@gmx.net \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.com \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).