aboutsummaryrefslogtreecommitdiffstats
path: root/common_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'common_test.go')
-rw-r--r--common_test.go31
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{})