diff options
author | Paulo Gomes <pjbgf@linux.com> | 2023-10-09 21:37:49 +0100 |
---|---|---|
committer | Paulo Gomes <paulo.gomes@suse.com> | 2023-11-17 20:06:41 +0000 |
commit | 2e14e3ab84edd9b0f54b355aeddfcadf1383ec67 (patch) | |
tree | e20dc5c5d555dcc52957618d537302d2a100fea5 /plumbing | |
parent | 6d62dd1250a41ffe6d04794fb2e460456ebaea91 (diff) | |
download | go-git-2e14e3ab84edd9b0f54b355aeddfcadf1383ec67.tar.gz |
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 <pjbgf@linux.com>
Diffstat (limited to 'plumbing')
-rw-r--r-- | plumbing/transport/git/common_test.go | 20 |
1 files changed, 15 insertions, 5 deletions
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) { |