aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_utils.go
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/test_utils.go
parentea5a752ee66f5f8dccbc058c4e1220e24e01b3e8 (diff)
downloadgitea-a2779def36590518157c4315a02e7cbaefcecb92.tar.gz
gitea-a2779def36590518157c4315a02e7cbaefcecb92.zip
Test views of LFS files (#22196)
Diffstat (limited to 'tests/test_utils.go')
-rw-r--r--tests/test_utils.go28
1 files changed, 28 insertions, 0 deletions
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
+ }))
}