Use repo as of renderctx's member rather than a repoPath on metas (#29222)
Use a `gitrepo.Repository` in the markup's RenderContext but not store the repository's path.
This commit is contained in:
parent
d612a24e3e
commit
015efcd8bf
19 changed files with 135 additions and 48 deletions
|
@ -4,16 +4,13 @@
|
|||
package markup_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
"code.gitea.io/gitea/modules/emoji"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
"code.gitea.io/gitea/modules/gitrepo"
|
||||
"code.gitea.io/gitea/modules/markup"
|
||||
"code.gitea.io/gitea/modules/markup/markdown"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
@ -22,18 +19,33 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var localMetas = map[string]string{
|
||||
"user": "gogits",
|
||||
"repo": "gogs",
|
||||
"repoPath": "../../tests/gitea-repositories-meta/user13/repo11.git/",
|
||||
var (
|
||||
testRepoOwnerName = "user13"
|
||||
testRepoName = "repo11"
|
||||
localMetas = map[string]string{
|
||||
"user": testRepoOwnerName,
|
||||
"repo": testRepoName,
|
||||
}
|
||||
)
|
||||
|
||||
type mockRepo struct {
|
||||
OwnerName string
|
||||
RepoName string
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
unittest.InitSettings()
|
||||
if err := git.InitSimple(context.Background()); err != nil {
|
||||
log.Fatal("git init failed, err: %v", err)
|
||||
func (m *mockRepo) GetOwnerName() string {
|
||||
return m.OwnerName
|
||||
}
|
||||
|
||||
func (m *mockRepo) GetName() string {
|
||||
return m.RepoName
|
||||
}
|
||||
|
||||
func newMockRepo(ownerName, repoName string) gitrepo.Repository {
|
||||
return &mockRepo{
|
||||
OwnerName: ownerName,
|
||||
RepoName: repoName,
|
||||
}
|
||||
os.Exit(m.Run())
|
||||
}
|
||||
|
||||
func TestRender_Commits(t *testing.T) {
|
||||
|
@ -46,6 +58,7 @@ func TestRender_Commits(t *testing.T) {
|
|||
AbsolutePrefix: true,
|
||||
Base: markup.TestRepoURL,
|
||||
},
|
||||
Repo: newMockRepo(testRepoOwnerName, testRepoName),
|
||||
Metas: localMetas,
|
||||
}, input)
|
||||
assert.NoError(t, err)
|
||||
|
@ -53,7 +66,7 @@ func TestRender_Commits(t *testing.T) {
|
|||
}
|
||||
|
||||
sha := "65f1bf27bc3bf70f64657658635e66094edbcb4d"
|
||||
repo := markup.TestRepoURL
|
||||
repo := markup.TestAppURL + testRepoOwnerName + "/" + testRepoName + "/"
|
||||
commit := util.URLJoin(repo, "commit", sha)
|
||||
tree := util.URLJoin(repo, "tree", sha, "src")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue