mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-02 19:39:49 +02:00
Prevent services/mailer/mailer_test.go tests from deleteing data directory (#17941)
Running `make test-backend` will delete `data/` due to reloading the configuration and resetting the appdatapath. This PR removes this unnecessary config reload but also adds extra code in to the unittest main to prevent its cleanup from deleting the wrong directory. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
1 parent
3ca5dc7e32
commit
f550e356d6
3 files changed
+23
-13
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
@@ -57,6 +58,14 @@ func TestMain(m *testing.M) {
|
||||
setting.CustomConf = giteaConf
|
||||
}
|
||||
|
||||
tmpDataPath, err := ioutil.TempDir("", "data")
|
||||
if err != nil {
|
||||
fmt.Printf("Unable to create temporary data path %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
setting.AppDataPath = tmpDataPath
|
||||
|
||||
setting.SetCustomPathAndConf("", "", "")
|
||||
setting.LoadForTest()
|
||||
git.CheckLFSVersion()
|
||||
@@ -68,7 +77,7 @@ func TestMain(m *testing.M) {
|
||||
if err := removeAllWithRetry(setting.RepoRootPath); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
|
||||
}
|
||||
if err := removeAllWithRetry(setting.AppDataPath); err != nil {
|
||||
if err := removeAllWithRetry(tmpDataPath); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
|
||||
}
|
||||
os.Exit(exitStatus)
|
||||
|
||||
Reference in new issue
Block a user