aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNick <nick.guenther@polymtl.ca>2022-12-22 18:41:56 -0500
committerGitHub <noreply@github.com>2022-12-23 07:41:56 +0800
commita2779def36590518157c4315a02e7cbaefcecb92 (patch)
treeb7f9071ed8343842436eee5679c516dd8c982764 /tests
parentea5a752ee66f5f8dccbc058c4e1220e24e01b3e8 (diff)
downloadgitea-a2779def36590518157c4315a02e7cbaefcecb92.tar.gz
gitea-a2779def36590518157c4315a02e7cbaefcecb92.zip
Test views of LFS files (#22196)
Diffstat (limited to 'tests')
-rw-r--r--tests/gitea-lfs-meta/0b/8d/8b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351bin0 -> 107 bytes
-rw-r--r--tests/gitea-lfs-meta/2e/cc/db43825d2a49d99d542daa20075cff1d97d9d2349a8977efe9c03661737cbin0 -> 2048 bytes
-rw-r--r--tests/gitea-lfs-meta/7b/6b/2c88dba9f760a1a58469b67fee2b698ef7e9399c4ca4f34a14ccbe39f6231
-rw-r--r--tests/gitea-lfs-meta/9d/17/2e5c64b4f0024b9901ec6afe9ea052f3c9b6ff9f4b07956d8c48c86fca821
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/HEAD1
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/config4
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/15/2de0f78bc6815b58cd9f08aebe3f66fb0f172ebin0 -> 228 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/23/10e4a07f9314a1a92fdfbdcd3d2884f01e96abbin0 -> 123 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/2b/6c6c4eaefa24b22f2092c3d54b263ff26feb58bin0 -> 122 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/73/cf03db6ece34e12bf91e8853dc58f678f2f82d2
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/74/21a018a7e3f15ee5691f162d0ed87dc19882f0bin0 -> 123 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/82/76d2a29779af982c0afa976bdb793b52d442a8bin0 -> 38 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/bc/e50ea8f203ee923d5a640d05208abf3206486ebin0 -> 92 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/d4/a41a0d4db4949e129bd22f871171ea988103efbin0 -> 123 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/d7/ce0013ced38b0696dd2d68d69a5d8b652f7148bin0 -> 55 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/objects/df/d8105b264d304c49ed9f1d56bd90189ecdf833bin0 -> 75 bytes
-rw-r--r--tests/gitea-repositories-meta/user2/lfs.git/refs/heads/master1
-rw-r--r--tests/integration/lfs_view_test.go83
-rw-r--r--tests/test_utils.go28
19 files changed, 121 insertions, 0 deletions
diff --git a/tests/gitea-lfs-meta/0b/8d/8b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351 b/tests/gitea-lfs-meta/0b/8d/8b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351
new file mode 100644
index 0000000000..71911bf487
--- /dev/null
+++ b/tests/gitea-lfs-meta/0b/8d/8b5f15046343fd32f451df93acc2bdd9e6373be478b968e4cad6b6647351
Binary files differ
diff --git a/tests/gitea-lfs-meta/2e/cc/db43825d2a49d99d542daa20075cff1d97d9d2349a8977efe9c03661737c b/tests/gitea-lfs-meta/2e/cc/db43825d2a49d99d542daa20075cff1d97d9d2349a8977efe9c03661737c
new file mode 100644
index 0000000000..1e16a25b6a
--- /dev/null
+++ b/tests/gitea-lfs-meta/2e/cc/db43825d2a49d99d542daa20075cff1d97d9d2349a8977efe9c03661737c
Binary files differ
diff --git a/tests/gitea-lfs-meta/7b/6b/2c88dba9f760a1a58469b67fee2b698ef7e9399c4ca4f34a14ccbe39f623 b/tests/gitea-lfs-meta/7b/6b/2c88dba9f760a1a58469b67fee2b698ef7e9399c4ca4f34a14ccbe39f623
new file mode 100644
index 0000000000..378de496da
--- /dev/null
+++ b/tests/gitea-lfs-meta/7b/6b/2c88dba9f760a1a58469b67fee2b698ef7e9399c4ca4f34a14ccbe39f623
@@ -0,0 +1 @@
+# Testing documents in LFS
diff --git a/tests/gitea-lfs-meta/9d/17/2e5c64b4f0024b9901ec6afe9ea052f3c9b6ff9f4b07956d8c48c86fca82 b/tests/gitea-lfs-meta/9d/17/2e5c64b4f0024b9901ec6afe9ea052f3c9b6ff9f4b07956d8c48c86fca82
new file mode 100644
index 0000000000..7eb6670a31
--- /dev/null
+++ b/tests/gitea-lfs-meta/9d/17/2e5c64b4f0024b9901ec6afe9ea052f3c9b6ff9f4b07956d8c48c86fca82
@@ -0,0 +1 @@
+# Testing READMEs in LFS
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/HEAD b/tests/gitea-repositories-meta/user2/lfs.git/HEAD
new file mode 100644
index 0000000000..cb089cd89a
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/HEAD
@@ -0,0 +1 @@
+ref: refs/heads/master
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/config b/tests/gitea-repositories-meta/user2/lfs.git/config
new file mode 100644
index 0000000000..07d359d07c
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/config
@@ -0,0 +1,4 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/15/2de0f78bc6815b58cd9f08aebe3f66fb0f172e b/tests/gitea-repositories-meta/user2/lfs.git/objects/15/2de0f78bc6815b58cd9f08aebe3f66fb0f172e
new file mode 100644
index 0000000000..d6657772ed
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/15/2de0f78bc6815b58cd9f08aebe3f66fb0f172e
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/23/10e4a07f9314a1a92fdfbdcd3d2884f01e96ab b/tests/gitea-repositories-meta/user2/lfs.git/objects/23/10e4a07f9314a1a92fdfbdcd3d2884f01e96ab
new file mode 100644
index 0000000000..16a791a4ab
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/23/10e4a07f9314a1a92fdfbdcd3d2884f01e96ab
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/2b/6c6c4eaefa24b22f2092c3d54b263ff26feb58 b/tests/gitea-repositories-meta/user2/lfs.git/objects/2b/6c6c4eaefa24b22f2092c3d54b263ff26feb58
new file mode 100644
index 0000000000..d8d55b14fa
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/2b/6c6c4eaefa24b22f2092c3d54b263ff26feb58
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/73/cf03db6ece34e12bf91e8853dc58f678f2f82d b/tests/gitea-repositories-meta/user2/lfs.git/objects/73/cf03db6ece34e12bf91e8853dc58f678f2f82d
new file mode 100644
index 0000000000..5eee31d8aa
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/73/cf03db6ece34e12bf91e8853dc58f678f2f82d
@@ -0,0 +1,2 @@
+xQ
+B!EvbƗAD70V¹'RrMY0Y";28:/AĜ&Z_6]g\dk9%ihXG?O]g@}97 \ No newline at end of file
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/74/21a018a7e3f15ee5691f162d0ed87dc19882f0 b/tests/gitea-repositories-meta/user2/lfs.git/objects/74/21a018a7e3f15ee5691f162d0ed87dc19882f0
new file mode 100644
index 0000000000..cbbde812d7
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/74/21a018a7e3f15ee5691f162d0ed87dc19882f0
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/82/76d2a29779af982c0afa976bdb793b52d442a8 b/tests/gitea-repositories-meta/user2/lfs.git/objects/82/76d2a29779af982c0afa976bdb793b52d442a8
new file mode 100644
index 0000000000..cbee9fb5a0
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/82/76d2a29779af982c0afa976bdb793b52d442a8
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/bc/e50ea8f203ee923d5a640d05208abf3206486e b/tests/gitea-repositories-meta/user2/lfs.git/objects/bc/e50ea8f203ee923d5a640d05208abf3206486e
new file mode 100644
index 0000000000..83e8159975
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/bc/e50ea8f203ee923d5a640d05208abf3206486e
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/d4/a41a0d4db4949e129bd22f871171ea988103ef b/tests/gitea-repositories-meta/user2/lfs.git/objects/d4/a41a0d4db4949e129bd22f871171ea988103ef
new file mode 100644
index 0000000000..01f6e7bc63
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/d4/a41a0d4db4949e129bd22f871171ea988103ef
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/d7/ce0013ced38b0696dd2d68d69a5d8b652f7148 b/tests/gitea-repositories-meta/user2/lfs.git/objects/d7/ce0013ced38b0696dd2d68d69a5d8b652f7148
new file mode 100644
index 0000000000..53d1fe21e9
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/d7/ce0013ced38b0696dd2d68d69a5d8b652f7148
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/objects/df/d8105b264d304c49ed9f1d56bd90189ecdf833 b/tests/gitea-repositories-meta/user2/lfs.git/objects/df/d8105b264d304c49ed9f1d56bd90189ecdf833
new file mode 100644
index 0000000000..11940b8f79
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/objects/df/d8105b264d304c49ed9f1d56bd90189ecdf833
Binary files differ
diff --git a/tests/gitea-repositories-meta/user2/lfs.git/refs/heads/master b/tests/gitea-repositories-meta/user2/lfs.git/refs/heads/master
new file mode 100644
index 0000000000..8832a3e857
--- /dev/null
+++ b/tests/gitea-repositories-meta/user2/lfs.git/refs/heads/master
@@ -0,0 +1 @@
+73cf03db6ece34e12bf91e8853dc58f678f2f82d
diff --git a/tests/integration/lfs_view_test.go b/tests/integration/lfs_view_test.go
new file mode 100644
index 0000000000..1775fa629f
--- /dev/null
+++ b/tests/integration/lfs_view_test.go
@@ -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")
+ })
+}
diff --git a/tests/test_utils.go b/tests/test_utils.go
index b4bd4a011e..721edc86f8 100644
--- a/tests/test_utils.go
+++ b/tests/test_utils.go
@@ -167,7 +167,11 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
ourSkip += skip[0]
}
deferFn := PrintCurrentTest(t, ourSkip)
+
+ // load database fixtures
assert.NoError(t, unittest.LoadFixtures())
+
+ // load git repo fixtures
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
@@ -190,6 +194,16 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
}
}
+ // load LFS object fixtures
+ // (LFS storage can be on any of several backends, including remote servers, so we init it with the storage API)
+ lfsFixtures, err := storage.NewStorage("", storage.LocalStorageConfig{Path: path.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta")})
+ assert.NoError(t, err)
+ assert.NoError(t, storage.Clean(storage.LFS))
+ assert.NoError(t, lfsFixtures.IterateObjects(func(path string, _ storage.Object) error {
+ _, err := storage.Copy(storage.LFS, path, lfsFixtures, path)
+ return err
+ }))
+
return deferFn
}
@@ -198,7 +212,11 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() {
// within a single test this is required
func ResetFixtures(t *testing.T) {
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
+
+ // load database fixtures
assert.NoError(t, unittest.LoadFixtures())
+
+ // load git repo fixtures
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath))
ownerDirs, err := os.ReadDir(setting.RepoRootPath)
@@ -220,4 +238,14 @@ func ResetFixtures(t *testing.T) {
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755)
}
}
+
+ // load LFS object fixtures
+ // (LFS storage can be on any of several backends, including remote servers, so we init it with the storage API)
+ lfsFixtures, err := storage.NewStorage("", storage.LocalStorageConfig{Path: path.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta")})
+ assert.NoError(t, err)
+ assert.NoError(t, storage.Clean(storage.LFS))
+ assert.NoError(t, lfsFixtures.IterateObjects(func(path string, _ storage.Object) error {
+ _, err := storage.Copy(storage.LFS, path, lfsFixtures, path)
+ return err
+ }))
}