Skip to content

Commit f76b784

Browse files
committed
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 <[email protected]>
1 parent 7ef7dc7 commit f76b784

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

plumbing/transport/git/common_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git
22

33
import (
4+
"bytes"
45
"fmt"
56
"net"
67
"os"
@@ -32,7 +33,12 @@ func (s *BaseSuite) SetUpTest(c *C) {
3233
See https://github.com/git-for-windows/git/issues/907`)
3334
}
3435

35-
var err error
36+
cmd := exec.Command("git", "daemon", "--help")
37+
output, err := cmd.CombinedOutput()
38+
if err != nil && bytes.Contains(output, []byte("'daemon' is not a git command")) {
39+
c.Fatal("git daemon cannot be found")
40+
}
41+
3642
s.port, err = freePort()
3743
c.Assert(err, IsNil)
3844

@@ -85,11 +91,15 @@ func (s *BaseSuite) prepareRepository(c *C, f *fixtures.Fixture, name string) *t
8591
}
8692

8793
func (s *BaseSuite) TearDownTest(c *C) {
88-
_ = s.daemon.Process.Signal(os.Kill)
89-
_ = s.daemon.Wait()
94+
if s.daemon != nil {
95+
_ = s.daemon.Process.Signal(os.Kill)
96+
_ = s.daemon.Wait()
97+
}
9098

91-
err := os.RemoveAll(s.base)
92-
c.Assert(err, IsNil)
99+
if s.base != "" {
100+
err := os.RemoveAll(s.base)
101+
c.Assert(err, IsNil)
102+
}
93103
}
94104

95105
func freePort() (int, error) {

0 commit comments

Comments
 (0)