From 2e14e3ab84edd9b0f54b355aeddfcadf1383ec67 Mon Sep 17 00:00:00 2001 From: Paulo Gomes Date: Mon, 9 Oct 2023 21:37:49 +0100 Subject: plumbing: transport/git, Improve tests error message When running the tests in an install in which git daemon is not installed (e.g. openSUSE), all the git transport tests will fail with a connection refused error. This was due the git server not being running in the first place. The tests will now fail with 'git daemon cannot be found'. Signed-off-by: Paulo Gomes --- plumbing/transport/git/common_test.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'plumbing') diff --git a/plumbing/transport/git/common_test.go b/plumbing/transport/git/common_test.go index 7389919..3cab933 100644 --- a/plumbing/transport/git/common_test.go +++ b/plumbing/transport/git/common_test.go @@ -1,6 +1,7 @@ package git import ( + "bytes" "fmt" "net" "os" @@ -32,7 +33,12 @@ func (s *BaseSuite) SetUpTest(c *C) { See https://github.com/git-for-windows/git/issues/907`) } - var err error + cmd := exec.Command("git", "daemon", "--help") + output, err := cmd.CombinedOutput() + if err != nil && bytes.Contains(output, []byte("'daemon' is not a git command")) { + c.Fatal("git daemon cannot be found") + } + s.port, err = freePort() c.Assert(err, IsNil) @@ -85,11 +91,15 @@ func (s *BaseSuite) prepareRepository(c *C, f *fixtures.Fixture, name string) *t } func (s *BaseSuite) TearDownTest(c *C) { - _ = s.daemon.Process.Signal(os.Kill) - _ = s.daemon.Wait() + if s.daemon != nil { + _ = s.daemon.Process.Signal(os.Kill) + _ = s.daemon.Wait() + } - err := os.RemoveAll(s.base) - c.Assert(err, IsNil) + if s.base != "" { + err := os.RemoveAll(s.base) + c.Assert(err, IsNil) + } } func freePort() (int, error) { -- cgit