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

gitserver: Test for RepoDir #61853

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/gitserver/internal/gitserverfs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ go_test(
embed = [":gitserverfs"],
deps = [
"//cmd/gitserver/internal/common",
"//internal/api",
"//internal/observation",
"@com_github_sourcegraph_log//logtest",
"@com_github_stretchr_testify//assert",
],
Expand Down
38 changes: 38 additions & 0 deletions cmd/gitserver/internal/gitserverfs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,52 @@ package gitserverfs

import (
"path/filepath"
"strconv"
"testing"

"github.com/sourcegraph/log/logtest"
"github.com/stretchr/testify/assert"

"github.com/sourcegraph/sourcegraph/cmd/gitserver/internal/common"
"github.com/sourcegraph/sourcegraph/internal/api"
"github.com/sourcegraph/sourcegraph/internal/observation"
)

func TestGitserverFS_RepoDir(t *testing.T) {
fs := New(observation.TestContextTB(t), "/data/repos")

tts := []struct {
repoName api.RepoName
want string
}{
{
repoName: "github.com/sourcegraph/sourcegraph",
want: "/data/repos/github.com/sourcegraph/sourcegraph/.git",
},
{
repoName: "github.com/sourcegraph/sourcegraph.git",
want: "/data/repos/github.com/sourcegraph/sourcegraph.git/.git",
},
{
repoName: "DELETED-123123.123123-i.8713187.xyz/sourcegraph/sourcegraph",
want: "/data/repos/github.com/sourcegraph/sourcegraph/.git",
},
{
// This is invalid, but as a protection make sure that we still don't
// allow a path outside of /data/repos.
repoName: "github.com/sourcegraph/sourcegraph/../../../../../src-cli",
want: "/data/repos/src-cli/.git",
},
}

for i, tt := range tts {
t.Run(strconv.Itoa(i), func(t *testing.T) {
got := fs.RepoDir(tt.repoName).Path()
assert.Equal(t, tt.want, got)
})
}
}

func TestIgnorePath(t *testing.T) {
reposDir := "/data/repos"

Expand Down