diff options
author | Alberto Cortés <alcortesm@gmail.com> | 2017-02-13 16:05:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-13 16:05:33 +0100 |
commit | a69e1cf378db9eb86fe384ced9a295b5eba7943e (patch) | |
tree | 316ede9fa9d61aa7e401f59c4df3d7e687f608c2 | |
parent | d08446c5ad1c3523f1ba05255e38b9eda395408e (diff) | |
download | go-git-a69e1cf378db9eb86fe384ced9a295b5eba7943e.tar.gz |
transport/file: delete suite tmp dir at teardown (#266)
The transport/file common suite test generates a temporal directory; It is used to store the go-git client command and some links to it: git-upload-pack and git-receive-pack.
This directory is not deleted at the test teardown, so every time we run a test, we pollute "/tmp".
This patch adds a teardown function for the suite that deletes the temporal directory.
It also calls the teardown of the embedded fixtures.Suite, which is probably what we want also.
I have also simplify the call to ioutil.TempDir as it already uses the default tmp dir if no dir is provided.
-rw-r--r-- | plumbing/transport/file/common_test.go | 17 |
1 files changed, 12 insertions, 5 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) +} |