Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
- Date: Thu, 16 Mar 2017 13:58:57 -0400
- From: Jeff King <peff@xxxxxxxx>
- Subject: Re: [GSoC][PATCH v4 4/4] credential-cache: add tests for XDG functionality
On Thu, Mar 16, 2017 at 09:29:58AM -0700, Junio C Hamano wrote:
> Devin Lehmacher <lehmacdj@xxxxxxxxx> writes:
> > @@ -20,4 +21,67 @@ helper_test_timeout cache --timeout=1
> > # our socket, leaving us with no way to access the daemon.
> > git credential-cache exit
> > +# we need to use rm -rf here since sometimes the daemon hasn't finished
> > +# cleaning up after itself and rmdir fails
> Hmmmm. Peff, do you have ideas on better ways to do this (or
> explanation why this is the best we could do)?
If you call "git credential-cache exit", that should be deterministic.
The client program won't exit until the other side closes the
descriptor, which it won't do until it has cleaned up the socket. See
the comment at line 130 of credential-cache--daemon.c.
> > +test_expect_success 'credential-cache --socket option overrides default location' '
> > + test_when_finished "rm -rf \"$HOME\"/dir/" &&
> > + check approve "cache --socket \"$HOME/dir/socket\"" <<-\EOF &&
> > + protocol=https
> > + host=example.com
> > + username=store-user
> > + password=store-pass
> > + EOF
> > + test -S "$HOME/dir/socket" &&
> > + git credential-cache exit
> > +'
This is almost right, except:
- the "exit" needs to be told which socket to use
- we should do the "exit" even when the test fails early (so in
- the test_when_finished block will interpolate $HOME when setting up
the block, which will break if it contains double-quotes or other
special characters. It should use \$HOME.
I suspect the "check" invocation needs to do so as well, though it
is even trickier (we shove it into a single-quoted "-c" argument).
I think you could get by in both cases with relative paths.
So all together, probably:
git credential-cache --socket dir/socket &&
check approve "cache --socket dir/socket" <<-\EOF &&
test -S dir/socket
The final "test -S" should be OK in practice. We're assuming that the
cache-daemon is still running, but it has a 900 second timeout by
default (and besides, all the other tests have exact same race).