aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-11 11:17:04 +1000
committerArieh Schneier <15041913+AriehSchneier@users.noreply.github.com>2023-05-11 11:17:04 +1000
commitb8dd39abcc9dd35808ec625a90a68c0ace4973e4 (patch)
tree513a5972fca375657cbf904c4153987e506f8cf0
parent1dbd729a387edb61c89f088cd68040085e6c81bb (diff)
downloadgo-git-b8dd39abcc9dd35808ec625a90a68c0ace4973e4.tar.gz
git: Testing, Fix tests not cleaning temp folders
Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com>
-rw-r--r--common_test.go24
-rw-r--r--repository_test.go18
-rw-r--r--submodule_test.go16
3 files changed, 31 insertions, 27 deletions
diff --git a/common_test.go b/common_test.go
index c0c4009..3311a17 100644
--- a/common_test.go
+++ b/common_test.go
@@ -37,7 +37,7 @@ func (s *BaseSuite) TearDownSuite(c *C) {
s.Suite.TearDownSuite(c)
}
-func (s *BaseSuite) buildBasicRepository(c *C) {
+func (s *BaseSuite) buildBasicRepository(_ *C) {
f := fixtures.Basic().One()
s.Repository = s.NewRepository(f)
}
@@ -105,13 +105,16 @@ func (s *BaseSuite) NewRepositoryFromPackfile(f *fixtures.Fixture) *Repository {
storer := memory.NewStorage()
p := f.Packfile()
- defer p.Close()
+ defer func() { _ = p.Close() }()
if err := packfile.UpdateObjectStorage(storer, p); err != nil {
panic(err)
}
- storer.SetReference(plumbing.NewHashReference(plumbing.HEAD, plumbing.NewHash(f.Head)))
+ err := storer.SetReference(plumbing.NewHashReference(plumbing.HEAD, plumbing.NewHash(f.Head)))
+ if err != nil {
+ panic(err)
+ }
r, err := Open(storer, memfs.New())
if err != nil {
@@ -133,14 +136,17 @@ func (s *BaseSuite) GetLocalRepositoryURL(f *fixtures.Fixture) string {
func (s *BaseSuite) TemporalDir() (path string, clean func()) {
fs := osfs.New(os.TempDir())
- path, err := util.TempDir(fs, "", "")
+ relPath, err := util.TempDir(fs, "", "")
if err != nil {
panic(err)
}
- return fs.Join(fs.Root(), path), func() {
- util.RemoveAll(fs, path)
+ path = fs.Join(fs.Root(), relPath)
+ clean = func() {
+ _ = util.RemoveAll(fs, relPath)
}
+
+ return
}
func (s *BaseSuite) TemporalFilesystem() (fs billy.Filesystem, clean func()) {
@@ -155,9 +161,11 @@ func (s *BaseSuite) TemporalFilesystem() (fs billy.Filesystem, clean func()) {
panic(err)
}
- return fs, func() {
- util.RemoveAll(fs, path)
+ clean = func() {
+ _ = util.RemoveAll(fs, path)
}
+
+ return
}
type SuiteCommon struct{}
diff --git a/repository_test.go b/repository_test.go
index 0080a83..45af396 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
- "io/ioutil"
"os"
"os/exec"
"path/filepath"
@@ -60,17 +59,18 @@ func (s *RepositorySuite) TestInitNonStandardDotGit(c *C) {
fs := osfs.New(dir)
dot, _ := fs.Chroot("storage")
- storage := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
+ st := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
wt, _ := fs.Chroot("worktree")
- r, err := Init(storage, wt)
+ r, err := Init(st, wt)
c.Assert(err, IsNil)
c.Assert(r, NotNil)
f, err := fs.Open(fs.Join("worktree", ".git"))
c.Assert(err, IsNil)
+ defer func() { _ = f.Close() }()
- all, err := ioutil.ReadAll(f)
+ all, err := io.ReadAll(f)
c.Assert(err, IsNil)
c.Assert(string(all), Equals, fmt.Sprintf("gitdir: %s\n", filepath.Join("..", "storage")))
@@ -85,9 +85,9 @@ func (s *RepositorySuite) TestInitStandardDotGit(c *C) {
fs := osfs.New(dir)
dot, _ := fs.Chroot(".git")
- storage := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
+ st := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
- r, err := Init(storage, fs)
+ r, err := Init(st, fs)
c.Assert(err, IsNil)
c.Assert(r, NotNil)
@@ -3009,14 +3009,14 @@ func BenchmarkObjects(b *testing.B) {
b.Run(f.URL, func(b *testing.B) {
fs := f.DotGit()
- storer := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
+ st := filesystem.NewStorage(fs, cache.NewObjectLRUDefault())
worktree, err := fs.Chroot(filepath.Dir(fs.Root()))
if err != nil {
b.Fatal(err)
}
- repo, err := Open(storer, worktree)
+ repo, err := Open(st, worktree)
if err != nil {
b.Fatal(err)
}
@@ -3046,7 +3046,7 @@ func BenchmarkObjects(b *testing.B) {
func BenchmarkPlainClone(b *testing.B) {
for i := 0; i < b.N; i++ {
- t, err := ioutil.TempDir("", "")
+ t, err := os.MkdirTemp("", "")
if err != nil {
b.Fatal(err)
}
diff --git a/submodule_test.go b/submodule_test.go
index a8a0681..92943e1 100644
--- a/submodule_test.go
+++ b/submodule_test.go
@@ -2,7 +2,6 @@ package git
import (
"context"
- "os"
"path/filepath"
"testing"
@@ -15,7 +14,7 @@ import (
type SubmoduleSuite struct {
BaseSuite
Worktree *Worktree
- path string
+ clean func()
}
var _ = Suite(&SubmoduleSuite{})
@@ -23,8 +22,8 @@ var _ = Suite(&SubmoduleSuite{})
func (s *SubmoduleSuite) SetUpTest(c *C) {
path := fixtures.ByTag("submodule").One().Worktree().Root()
- dir, clean := s.TemporalDir()
- defer clean()
+ var dir string
+ dir, s.clean = s.TemporalDir()
r, err := PlainClone(filepath.Join(dir, "worktree"), false, &CloneOptions{
URL: path,
@@ -35,13 +34,10 @@ func (s *SubmoduleSuite) SetUpTest(c *C) {
s.Repository = r
s.Worktree, err = r.Worktree()
c.Assert(err, IsNil)
-
- s.path = dir
}
-func (s *SubmoduleSuite) TearDownTest(c *C) {
- err := os.RemoveAll(s.path)
- c.Assert(err, IsNil)
+func (s *SubmoduleSuite) TearDownTest(_ *C) {
+ s.clean()
}
func (s *SubmoduleSuite) TestInit(c *C) {
@@ -198,7 +194,7 @@ func (s *SubmoduleSuite) TestSubmodulesInit(c *C) {
func (s *SubmoduleSuite) TestGitSubmodulesSymlink(c *C) {
f, err := s.Worktree.Filesystem.Create("badfile")
c.Assert(err, IsNil)
- defer f.Close()
+ defer func() { _ = f.Close() }()
err = s.Worktree.Filesystem.Remove(gitmodulesFile)
c.Assert(err, IsNil)