From 01df7536992af375a54bbedf45369a475953e372 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Sun, 2 May 2021 23:40:08 +0200 Subject: *: use go-billy instead of os calls --- common_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'common_test.go') diff --git a/common_test.go b/common_test.go index 8154359..5f5bc4c 100644 --- a/common_test.go +++ b/common_test.go @@ -1,6 +1,7 @@ package git import ( + "os" "testing" "github.com/go-git/go-git/v5/plumbing" @@ -12,6 +13,7 @@ import ( "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" + "github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-billy/v5/util" fixtures "github.com/go-git/go-git-fixtures/v4" . "gopkg.in/check.v1" @@ -131,6 +133,35 @@ func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string { return f.DotGit().Root() } +func (s *BaseSuite) TemporalDir() (path string, clean func()) { + fs := osfs.New(os.TempDir()) + path, err := util.TempDir(fs, "", "") + if err != nil { + panic(err) + } + + return fs.Join(fs.Root(), path), func() { + util.RemoveAll(fs, path) + } +} + +func (s *BaseSuite) TemporalFilesystem() (fs billy.Filesystem, clean func()) { + fs = osfs.New(os.TempDir()) + path, err := util.TempDir(fs, "", "") + if err != nil { + panic(err) + } + + fs, err = fs.Chroot(path) + if err != nil { + panic(err) + } + + return fs, func() { + util.RemoveAll(fs, path) + } +} + type SuiteCommon struct{} var _ = Suite(&SuiteCommon{}) -- cgit