mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 10:33:20 +00:00
49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package files
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
"code.gitea.io/gitea/modules/contexttest"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestNewRepoGrep(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
ctx, _ := contexttest.MockContext(t, "user2/repo1")
|
|
ctx.SetParams(":id", "1")
|
|
contexttest.LoadRepo(t, ctx, 1)
|
|
contexttest.LoadRepoCommit(t, ctx)
|
|
contexttest.LoadUser(t, ctx, 2)
|
|
contexttest.LoadGitRepo(t, ctx)
|
|
defer ctx.Repo.GitRepo.Close()
|
|
|
|
t.Run("with result", func(t *testing.T) {
|
|
res, err := NewRepoGrep(ctx, ctx.Repo.Repository, "Description")
|
|
assert.NoError(t, err)
|
|
|
|
expected := []*Result{
|
|
{
|
|
RepoID: 0,
|
|
Filename: "README.md",
|
|
CommitID: "master",
|
|
UpdatedUnix: 0,
|
|
Language: "Markdown",
|
|
Color: "#083fa1",
|
|
LineNumbers: []int64{2, 3},
|
|
FormattedLines: "\nDescription for repo1",
|
|
},
|
|
}
|
|
|
|
assert.EqualValues(t, res, expected)
|
|
})
|
|
|
|
t.Run("empty result", func(t *testing.T) {
|
|
res, err := NewRepoGrep(ctx, ctx.Repo.Repository, "keyword that does not match in the repo")
|
|
assert.NoError(t, err)
|
|
|
|
assert.EqualValues(t, res, []*Result{})
|
|
})
|
|
}
|