diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-21 16:03:39 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-02-21 16:03:39 +0100 |
commit | ed288b30de1ac3dcb3ce675c4b9af89eb4e6fcba (patch) | |
tree | 6eb908b839d6c225d95691d91e3d5ef5220f54c1 /plumbing/transport/file | |
parent | d6a6decd1be0515faf36256ce06c58c7d662bbd0 (diff) | |
download | go-git-ed288b30de1ac3dcb3ce675c4b9af89eb4e6fcba.tar.gz |
documentation and API improvements
Diffstat (limited to 'plumbing/transport/file')
-rw-r--r-- | plumbing/transport/file/common_test.go | 17 | ||||
-rw-r--r-- | plumbing/transport/file/server_test.go | 49 |
2 files changed, 16 insertions, 50 deletions
diff --git a/plumbing/transport/file/common_test.go b/plumbing/transport/file/common_test.go index 3dc4500..4f3ae8f 100644 --- a/plumbing/transport/file/common_test.go +++ b/plumbing/transport/file/common_test.go @@ -1,6 +1,7 @@ package file import ( + "io/ioutil" "os" "os/exec" "path/filepath" @@ -8,13 +9,13 @@ import ( "github.com/src-d/go-git-fixtures" . "gopkg.in/check.v1" - "io/ioutil" ) type CommonSuite struct { fixtures.Suite ReceivePackBin string UploadPackBin string + tmpDir string // to be removed at teardown } var _ = Suite(&CommonSuite{}) @@ -26,14 +27,20 @@ func (s *CommonSuite) SetUpSuite(c *C) { c.Skip("git command not found") } - binDir, err := ioutil.TempDir(os.TempDir(), "") + var err error + s.tmpDir, err = ioutil.TempDir("", "") c.Assert(err, IsNil) - s.ReceivePackBin = filepath.Join(binDir, "git-receive-pack") - s.UploadPackBin = filepath.Join(binDir, "git-upload-pack") - bin := filepath.Join(binDir, "go-git") + s.ReceivePackBin = filepath.Join(s.tmpDir, "git-receive-pack") + s.UploadPackBin = filepath.Join(s.tmpDir, "git-upload-pack") + bin := filepath.Join(s.tmpDir, "go-git") cmd := exec.Command("go", "build", "-o", bin, "../../../cli/go-git/...") c.Assert(cmd.Run(), IsNil) c.Assert(os.Symlink(bin, s.ReceivePackBin), IsNil) c.Assert(os.Symlink(bin, s.UploadPackBin), IsNil) } + +func (s *CommonSuite) TearDownSuite(c *C) { + defer s.Suite.TearDownSuite(c) + c.Assert(os.RemoveAll(s.tmpDir), IsNil) +} diff --git a/plumbing/transport/file/server_test.go b/plumbing/transport/file/server_test.go index 775b031..a7b4e34 100644 --- a/plumbing/transport/file/server_test.go +++ b/plumbing/transport/file/server_test.go @@ -2,8 +2,6 @@ package file import ( "fmt" - "io" - "io/ioutil" "os" "os/exec" @@ -48,8 +46,8 @@ func (s *ServerSuite) TestPush(c *C) { cmd.Dir = s.SrcPath cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true") - stdout, stderr, err := execAndGetOutput(c, cmd) - c.Assert(err, IsNil, Commentf("STDOUT:\n%s\nSTDERR:\n%s\n", stdout, stderr)) + out, err := cmd.CombinedOutput() + c.Assert(err, IsNil, Commentf("combined stdout and stderr:\n%s\n", out)) } func (s *ServerSuite) TestClone(c *C) { @@ -61,45 +59,6 @@ func (s *ServerSuite) TestClone(c *C) { ) cmd.Env = os.Environ() cmd.Env = append(cmd.Env, "GIT_TRACE=true", "GIT_TRACE_PACKET=true") - stdout, stderr, err := execAndGetOutput(c, cmd) - c.Assert(err, IsNil, Commentf("STDOUT:\n%s\nSTDERR:\n%s\n", stdout, stderr)) -} - -func execAndGetOutput(c *C, cmd *exec.Cmd) (stdout, stderr string, err error) { - sout, err := cmd.StdoutPipe() - c.Assert(err, IsNil) - serr, err := cmd.StderrPipe() - c.Assert(err, IsNil) - - outChan, outErr := readAllAsync(sout) - errChan, errErr := readAllAsync(serr) - - c.Assert(cmd.Start(), IsNil) - - if err = cmd.Wait(); err != nil { - return <-outChan, <-errChan, err - } - - if err := <-outErr; err != nil { - return <-outChan, <-errChan, err - } - - return <-outChan, <-errChan, <-errErr -} - -func readAllAsync(r io.Reader) (out chan string, err chan error) { - out = make(chan string, 1) - err = make(chan error, 1) - go func() { - b, e := ioutil.ReadAll(r) - if e != nil { - err <- e - } else { - err <- nil - } - - out <- string(b) - }() - - return out, err + out, err := cmd.CombinedOutput() + c.Assert(err, IsNil, Commentf("combined stdout and stderr:\n%s\n", out)) } |