@@ -2,14 +2,52 @@ package gitserverfs
2
2
3
3
import (
4
4
"path/filepath"
5
+ "strconv"
5
6
"testing"
6
7
7
8
"github.com/sourcegraph/log/logtest"
8
9
"github.com/stretchr/testify/assert"
9
10
10
11
"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/common"
12
+ "github.com/sourcegraph/sourcegraph/internal/api"
13
+ "github.com/sourcegraph/sourcegraph/internal/observation"
11
14
)
12
15
16
+ func TestGitserverFS_RepoDir (t * testing.T ) {
17
+ fs := New (observation .TestContextTB (t ), "/data/repos" )
18
+
19
+ tts := []struct {
20
+ repoName api.RepoName
21
+ want string
22
+ }{
23
+ {
24
+ repoName : "github.com/sourcegraph/sourcegraph" ,
25
+ want : "/data/repos/github.com/sourcegraph/sourcegraph/.git" ,
26
+ },
27
+ {
28
+ repoName : "github.com/sourcegraph/sourcegraph.git" ,
29
+ want : "/data/repos/github.com/sourcegraph/sourcegraph.git/.git" ,
30
+ },
31
+ {
32
+ repoName : "DELETED-123123.123123-i.8713187.xyz/sourcegraph/sourcegraph" ,
33
+ want : "/data/repos/github.com/sourcegraph/sourcegraph/.git" ,
34
+ },
35
+ {
36
+ // This is invalid, but as a protection make sure that we still don't
37
+ // allow a path outside of /data/repos.
38
+ repoName : "github.com/sourcegraph/sourcegraph/../../../../../src-cli" ,
39
+ want : "/data/repos/src-cli/.git" ,
40
+ },
41
+ }
42
+
43
+ for i , tt := range tts {
44
+ t .Run (strconv .Itoa (i ), func (t * testing.T ) {
45
+ got := fs .RepoDir (tt .repoName ).Path ()
46
+ assert .Equal (t , tt .want , got )
47
+ })
48
+ }
49
+ }
50
+
13
51
func TestIgnorePath (t * testing.T ) {
14
52
reposDir := "/data/repos"
15
53
0 commit comments