@@ -19,30 +19,8 @@ import (
19
19
)
20
20
21
21
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 ()
46
24
47
25
session := gitbase .NewSession (pool )
48
26
ctx := sql .NewContext (context .TODO (), sql .WithSession (session ))
@@ -105,3 +83,32 @@ func TestCommitStatsEval(t *testing.T) {
105
83
})
106
84
}
107
85
}
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