Skip to content

Commit 091ffb8

Browse files
committed
function: fix commit_file_stats_test.go
Signed-off-by: Javi Fontan <[email protected]>
1 parent cae8306 commit 091ffb8

File tree

2 files changed

+33
-35
lines changed

2 files changed

+33
-35
lines changed

internal/function/commit_file_stats_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,11 @@ import (
1010

1111
"github.com/src-d/go-mysql-server/sql"
1212
"github.com/src-d/go-mysql-server/sql/expression"
13-
fixtures "gopkg.in/src-d/go-git-fixtures.v3"
14-
"gopkg.in/src-d/go-git.v4/plumbing/cache"
1513
)
1614

1715
func TestCommitFileStats(t *testing.T) {
18-
require.NoError(t, fixtures.Init())
19-
defer func() {
20-
require.NoError(t, fixtures.Clean())
21-
}()
22-
23-
path := fixtures.ByTag("worktree").One().Worktree().Root()
24-
25-
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize)
26-
require.NoError(t, pool.AddGitWithID("worktree", path))
16+
pool, cleanup := setupPool(t)
17+
defer cleanup()
2718

2819
session := gitbase.NewSession(pool)
2920
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))

internal/function/commit_stats_test.go

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,8 @@ import (
1919
)
2020

2121
func TestCommitStatsEval(t *testing.T) {
22-
require.NoError(t, fixtures.Init())
23-
defer func() {
24-
require.NoError(t, fixtures.Clean())
25-
}()
26-
27-
path := fixtures.ByTag("worktree").One().Worktree().Root()
28-
pathLib := path + "-lib"
29-
pathRepo := filepath.Join(pathLib, "worktree")
30-
31-
err := os.MkdirAll(pathLib, 0777)
32-
require.NoError(t, err)
33-
defer func() {
34-
require.NoError(t, os.RemoveAll(pathLib))
35-
}()
36-
37-
err = os.Rename(path, pathRepo)
38-
require.NoError(t, err)
39-
40-
lib := plain.NewLibrary("plain")
41-
loc, err := plain.NewLocation("location", osfs.New(pathLib), nil)
42-
require.NoError(t, err)
43-
lib.AddLocation(loc)
44-
45-
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize, lib)
22+
pool, cleanup := setupPool(t)
23+
defer cleanup()
4624

4725
session := gitbase.NewSession(pool)
4826
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
@@ -105,3 +83,32 @@ func TestCommitStatsEval(t *testing.T) {
10583
})
10684
}
10785
}
86+
87+
func setupPool(t *testing.T) (*gitbase.RepositoryPool, func()) {
88+
t.Helper()
89+
require.NoError(t, fixtures.Init())
90+
91+
path := fixtures.ByTag("worktree").One().Worktree().Root()
92+
pathLib := path + "-lib"
93+
pathRepo := filepath.Join(pathLib, "worktree")
94+
95+
cleanup := func() {
96+
require.NoError(t, fixtures.Clean())
97+
require.NoError(t, os.RemoveAll(pathLib))
98+
}
99+
100+
err := os.MkdirAll(pathLib, 0777)
101+
require.NoError(t, err)
102+
103+
err = os.Rename(path, pathRepo)
104+
require.NoError(t, err)
105+
106+
lib := plain.NewLibrary("plain")
107+
loc, err := plain.NewLocation("location", osfs.New(pathLib), nil)
108+
require.NoError(t, err)
109+
lib.AddLocation(loc)
110+
111+
pool := gitbase.NewRepositoryPool(cache.DefaultMaxSize, lib)
112+
113+
return pool, cleanup
114+
}

0 commit comments

Comments
 (0)