|
|
@ -192,32 +192,7 @@ func PrepareAttachmentsStorage(t testing.TB) { |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func PrepareArtifactsStorage(t testing.TB) { |
|
|
|
func PrepareGitRepoDirectory(t testing.TB) { |
|
|
|
// prepare actions artifacts directory and files
|
|
|
|
|
|
|
|
assert.NoError(t, storage.Clean(storage.ActionsArtifacts)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{ |
|
|
|
|
|
|
|
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests", "testdata", "data", "artifacts"), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
assert.NoError(t, s.IterateObjects("", func(p string, obj storage.Object) error { |
|
|
|
|
|
|
|
_, err = storage.Copy(storage.ActionsArtifacts, p, s, p) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PrepareTestEnv(t testing.TB, skip ...int) func() { |
|
|
|
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
ourSkip := 1 |
|
|
|
|
|
|
|
if len(skip) > 0 { |
|
|
|
|
|
|
|
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, util.RemoveAll(setting.RepoRootPath)) |
|
|
|
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) |
|
|
|
assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) |
|
|
|
|
|
|
|
|
|
|
@ -241,12 +216,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() { |
|
|
|
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "pull"), 0o755) |
|
|
|
_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "pull"), 0o755) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Initialize actions artifact data
|
|
|
|
func PrepareArtifactsStorage(t testing.TB) { |
|
|
|
PrepareArtifactsStorage(t) |
|
|
|
// prepare actions artifacts directory and files
|
|
|
|
|
|
|
|
assert.NoError(t, storage.Clean(storage.ActionsArtifacts)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
s, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{ |
|
|
|
|
|
|
|
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests", "testdata", "data", "artifacts"), |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
assert.NoError(t, err) |
|
|
|
|
|
|
|
assert.NoError(t, s.IterateObjects("", func(p string, obj storage.Object) error { |
|
|
|
|
|
|
|
_, err = storage.Copy(storage.ActionsArtifacts, p, s, p) |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PrepareLFSStorage(t testing.TB) { |
|
|
|
// load LFS object fixtures
|
|
|
|
// load LFS object fixtures
|
|
|
|
// (LFS storage can be on any of several backends, including remote servers, so we init it with the storage API)
|
|
|
|
// (LFS storage can be on any of several backends, including remote servers, so init it with the storage API)
|
|
|
|
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{ |
|
|
|
lfsFixtures, err := storage.NewStorage(setting.LocalStorageType, &setting.Storage{ |
|
|
|
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta"), |
|
|
|
Path: filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-lfs-meta"), |
|
|
|
}) |
|
|
|
}) |
|
|
@ -256,7 +244,9 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() { |
|
|
|
_, err := storage.Copy(storage.LFS, path, lfsFixtures, path) |
|
|
|
_, err := storage.Copy(storage.LFS, path, lfsFixtures, path) |
|
|
|
return err |
|
|
|
return err |
|
|
|
})) |
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PrepareCleanPackageData(t testing.TB) { |
|
|
|
// clear all package data
|
|
|
|
// clear all package data
|
|
|
|
assert.NoError(t, db.TruncateBeans(db.DefaultContext, |
|
|
|
assert.NoError(t, db.TruncateBeans(db.DefaultContext, |
|
|
|
&packages_model.Package{}, |
|
|
|
&packages_model.Package{}, |
|
|
@ -268,17 +258,25 @@ func PrepareTestEnv(t testing.TB, skip ...int) func() { |
|
|
|
&packages_model.PackageCleanupRule{}, |
|
|
|
&packages_model.PackageCleanupRule{}, |
|
|
|
)) |
|
|
|
)) |
|
|
|
assert.NoError(t, storage.Clean(storage.Packages)) |
|
|
|
assert.NoError(t, storage.Clean(storage.Packages)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func PrepareTestEnv(t testing.TB, skip ...int) func() { |
|
|
|
|
|
|
|
t.Helper() |
|
|
|
|
|
|
|
deferFn := PrintCurrentTest(t, util.OptionalArg(skip)+1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// load database fixtures
|
|
|
|
|
|
|
|
assert.NoError(t, unittest.LoadFixtures()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// do not add more Prepare* functions here, only call necessary ones in the related test functions
|
|
|
|
|
|
|
|
PrepareGitRepoDirectory(t) |
|
|
|
|
|
|
|
PrepareLFSStorage(t) |
|
|
|
|
|
|
|
PrepareCleanPackageData(t) |
|
|
|
return deferFn |
|
|
|
return deferFn |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func PrintCurrentTest(t testing.TB, skip ...int) func() { |
|
|
|
func PrintCurrentTest(t testing.TB, skip ...int) func() { |
|
|
|
t.Helper() |
|
|
|
t.Helper() |
|
|
|
actualSkip := 1 |
|
|
|
return testlogger.PrintCurrentTest(t, util.OptionalArg(skip)+1) |
|
|
|
if len(skip) > 0 { |
|
|
|
|
|
|
|
actualSkip = skip[0] + 1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return testlogger.PrintCurrentTest(t, actualSkip) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Printf takes a format and args and prints the string to os.Stdout
|
|
|
|
// Printf takes a format and args and prints the string to os.Stdout
|
|
|
|