mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 13:39:19 -05:00
48d752c630
There are a number of tests which require creating a repository on the fly, and they each do it their own way. To reduce code duplication, lift out this common pattern into a helper called `CreateDeclarativeRepo()`, which lets us create a repository, set up enabled and disabled repo units, and even add, delete, or update files. Also convert a number of users of this pattern to the new helper - those users that I introduced, and are in code introduced by Forgejo in the first place. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit342b7bae3c
) (cherry picked from commit2ece8764e9
)
67 lines
1.8 KiB
Go
67 lines
1.8 KiB
Go
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package integration
|
|
|
|
import (
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
|
|
"code.gitea.io/gitea/models/unittest"
|
|
user_model "code.gitea.io/gitea/models/user"
|
|
files_service "code.gitea.io/gitea/services/repository/files"
|
|
"code.gitea.io/gitea/tests"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestUserProfile(t *testing.T) {
|
|
onGiteaRun(t, func(t *testing.T, u *url.URL) {
|
|
checkReadme := func(t *testing.T, title, readmeFilename string, expectedCount int) {
|
|
t.Run(title, func(t *testing.T) {
|
|
defer tests.PrintCurrentTest(t)()
|
|
|
|
// Prepare the test repository
|
|
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
|
|
|
var ops []*files_service.ChangeRepoFile
|
|
op := "create"
|
|
if readmeFilename != "README.md" {
|
|
ops = append(ops, &files_service.ChangeRepoFile{
|
|
Operation: "delete",
|
|
TreePath: "README.md",
|
|
})
|
|
} else {
|
|
op = "update"
|
|
}
|
|
if readmeFilename != "" {
|
|
ops = append(ops, &files_service.ChangeRepoFile{
|
|
Operation: op,
|
|
TreePath: readmeFilename,
|
|
ContentReader: strings.NewReader("# Hi!\n"),
|
|
})
|
|
}
|
|
|
|
_, _, f := CreateDeclarativeRepo(t, user2, ".profile", nil, nil, ops)
|
|
defer f()
|
|
|
|
// Perform the test
|
|
req := NewRequest(t, "GET", "/user2")
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
doc := NewHTMLParser(t, resp.Body)
|
|
readmeCount := doc.Find("#readme_profile").Length()
|
|
|
|
assert.Equal(t, expectedCount, readmeCount)
|
|
})
|
|
}
|
|
|
|
checkReadme(t, "No readme", "", 0)
|
|
checkReadme(t, "README.md", "README.md", 1)
|
|
checkReadme(t, "readme.md", "readme.md", 1)
|
|
checkReadme(t, "ReadMe.mD", "ReadMe.mD", 1)
|
|
checkReadme(t, "readme.org does not render", "README.org", 0)
|
|
})
|
|
}
|