diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2021-05-02 23:40:08 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2021-05-02 23:40:08 +0200 |
commit | 01df7536992af375a54bbedf45369a475953e372 (patch) | |
tree | 8435050f4388f15b3a85d135a3f7d11b1ff61540 /common_test.go | |
parent | 67af9d7223b0cc643025d958c592291f7475ac75 (diff) | |
download | go-git-01df7536992af375a54bbedf45369a475953e372.tar.gz |
*: use go-billy instead of os calls
Diffstat (limited to 'common_test.go')
-rw-r--r-- | common_test.go | 31 |
1 files changed, 31 insertions, 0 deletions
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{}) |