Skip to content
  • Jeff King's avatar
    t/lib-git-daemon: add network-protocol helpers · 4414a150
    Jeff King authored and Junio C Hamano's avatar Junio C Hamano committed
    
    
    All of our git-protocol tests rely on invoking the client
    and having it make a request of a server. That gives a nice
    real-world test of how the two behave together, but it
    doesn't leave any room for testing how a server might react
    to _other_ clients.
    
    Let's add a few test helper functions which can be used to
    manually conduct a git-protocol conversation with a remote
    git-daemon:
    
      1. To connect to a remote git-daemon, we need something
         like "netcat". But not everybody will have netcat. And
         even if they do, the behavior with respect to
         half-duplex shutdowns is not portable (openbsd netcat
         has "-N", with others you must rely on "-q 1", which is
         racy).
    
         Here we provide a "fake_nc" that is capable of doing
         a client-side netcat, with sane half-duplex semantics.
         It relies on perl's IO::Socket::INET. That's been in
         the base distribution since 5.6.0, so it's probably
         available everywhere. But just to be on the safe side,
         we'll add a prereq.
    
      2. To help tests speak and read pktline, this patch adds
         packetize() and depacketize() functions.
    
    I've put fake_nc() into lib-git-daemon.sh, since that's
    really the only server where we'd need to use a network
    socket.  Whereas the pktline helpers may be of more general
    use, so I've added them to test-lib-functions.sh. Programs
    like upload-pack speak pktline, but can talk directly over
    stdio without a network socket.
    
    Signed-off-by: default avatarJeff King <peff@peff.net>
    Signed-off-by: default avatarJunio C Hamano <gitster@pobox.com>
    4414a150