mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-07 16:27:00 +02:00
Merge remote-tracking branch 'upstream/main' into limit-repo-size
Conflicts: models/migrations/migrations.go models/migrations/v1_19/v237.go new file: models/migrations/v1_19/v238.go
This commit is contained in:
commit
2763393f39
98 files changed
+619
-362
No files matched your search
@@ -11,6 +11,8 @@ import (
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestEmptyRepo(t *testing.T) {
|
||||
@@ -21,7 +23,8 @@ func TestEmptyRepo(t *testing.T) {
|
||||
"commit/1ae57b34ccf7e18373",
|
||||
"graph",
|
||||
}
|
||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{}, unittest.Cond("is_empty = ?", true))
|
||||
emptyRepo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 5})
|
||||
assert.True(t, emptyRepo.IsEmpty)
|
||||
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: emptyRepo.OwnerID})
|
||||
for _, subpath := range subpaths {
|
||||
req := NewRequestf(t, "GET", "/%s/%s/%s", owner.Name, emptyRepo.Name, subpath)
|
||||
|
||||
@@ -209,8 +209,6 @@ func (s *TestSession) MakeRequestNilResponseHashSumRecorder(t testing.TB, req *h
|
||||
|
||||
const userPassword = "password"
|
||||
|
||||
var loginSessionCache = make(map[string]*TestSession, 10)
|
||||
|
||||
func emptyTestSession(t testing.TB) *TestSession {
|
||||
t.Helper()
|
||||
jar, err := cookiejar.New(nil)
|
||||
@@ -225,12 +223,8 @@ func getUserToken(t testing.TB, userName string) string {
|
||||
|
||||
func loginUser(t testing.TB, userName string) *TestSession {
|
||||
t.Helper()
|
||||
if session, ok := loginSessionCache[userName]; ok {
|
||||
return session
|
||||
}
|
||||
session := loginUserWithPassword(t, userName, userPassword)
|
||||
loginSessionCache[userName] = session
|
||||
return session
|
||||
|
||||
return loginUserWithPassword(t, userName, userPassword)
|
||||
}
|
||||
|
||||
func loginUserWithPassword(t testing.TB, userName, password string) *TestSession {
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
// Copyright 2022 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
|
||||
"code.gitea.io/gitea/tests"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// check that files stored in LFS render properly in the web UI
|
||||
func TestLFSRender(t *testing.T) {
|
||||
defer tests.PrepareTestEnv(t)()
|
||||
|
||||
session := loginUser(t, "user2")
|
||||
|
||||
// check that a markup file is flagged with "Stored in Git LFS" and shows its text
|
||||
t.Run("Markup", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/CONTRIBUTING.md")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc := NewHTMLParser(t, resp.Body).doc
|
||||
|
||||
fileInfo := doc.Find("div.file-info-entry").First().Text()
|
||||
assert.Contains(t, fileInfo, "Stored with Git LFS")
|
||||
|
||||
content := doc.Find("div.file-view").Text()
|
||||
assert.Contains(t, content, "Testing documents in LFS")
|
||||
})
|
||||
|
||||
// check that an image is flagged with "Stored in Git LFS" and renders inline
|
||||
t.Run("Image", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/jpeg.jpg")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc := NewHTMLParser(t, resp.Body).doc
|
||||
|
||||
fileInfo := doc.Find("div.file-info-entry").First().Text()
|
||||
assert.Contains(t, fileInfo, "Stored with Git LFS")
|
||||
|
||||
src, exists := doc.Find(".file-view img").Attr("src")
|
||||
assert.True(t, exists, "The image should be in an <img> tag")
|
||||
assert.Equal(t, "/user2/lfs/media/branch/master/jpeg.jpg", src, "The image should use the /media link because it's in LFS")
|
||||
})
|
||||
|
||||
// check that a binary file is flagged with "Stored in Git LFS" and renders a /media/ link instead of a /raw/ link
|
||||
t.Run("Binary", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/crypt.bin")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc := NewHTMLParser(t, resp.Body).doc
|
||||
|
||||
fileInfo := doc.Find("div.file-info-entry").First().Text()
|
||||
assert.Contains(t, fileInfo, "Stored with Git LFS")
|
||||
|
||||
rawLink, exists := doc.Find("div.file-view > div.view-raw > a").Attr("href")
|
||||
assert.True(t, exists, "Download link should render instead of content because this is a binary file")
|
||||
assert.Equal(t, "/user2/lfs/media/branch/master/crypt.bin", rawLink, "The download link should use the proper /media link because it's in LFS")
|
||||
})
|
||||
|
||||
// check that a directory with a README file shows its text
|
||||
t.Run("Readme", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user2/lfs/src/branch/master/subdir")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
|
||||
doc := NewHTMLParser(t, resp.Body).doc
|
||||
|
||||
content := doc.Find("div.file-view").Text()
|
||||
assert.Contains(t, content, "Testing READMEs in LFS")
|
||||
})
|
||||
}
|
||||
@@ -21,7 +21,4 @@ func TestSignOut(t *testing.T) {
|
||||
// try to view a private repo, should fail
|
||||
req = NewRequest(t, "GET", "/user2/repo2")
|
||||
session.MakeRequest(t, req, http.StatusNotFound)
|
||||
|
||||
// invalidate cached cookies for user2, for subsequent tests
|
||||
delete(loginSessionCache, "user2")
|
||||
}
|
||||
Reference in new issue
Block a user