Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit b0e31c8

Browse files
committed
gitserver: Test for RepoDir
Noticed this had no test and didn't feel super comfortable about that. Test plan: Added a test only.
1 parent b64422d commit b0e31c8

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

cmd/gitserver/internal/gitserverfs/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ go_test(
3535
embed = [":gitserverfs"],
3636
deps = [
3737
"//cmd/gitserver/internal/common",
38+
"//internal/api",
39+
"//internal/observation",
3840
"@com_github_sourcegraph_log//logtest",
3941
"@com_github_stretchr_testify//assert",
4042
],

cmd/gitserver/internal/gitserverfs/fs_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,52 @@ package gitserverfs
22

33
import (
44
"path/filepath"
5+
"strconv"
56
"testing"
67

78
"github.com/sourcegraph/log/logtest"
89
"github.com/stretchr/testify/assert"
910

1011
"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/common"
12+
"github.com/sourcegraph/sourcegraph/internal/api"
13+
"github.com/sourcegraph/sourcegraph/internal/observation"
1114
)
1215

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+
1351
func TestIgnorePath(t *testing.T) {
1452
reposDir := "/data/repos"
1553

0 commit comments

Comments
 (0)