Skip to content

Commit 3382a56

Browse files
committed
improvements
1 parent 178da31 commit 3382a56

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

models/migrations/base/tests.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,11 @@ func MainTest(m *testing.M) {
115115
setting.CustomConf = giteaConf
116116
}
117117

118-
tmpDataPath, _, err := temp.MkdirTemp("data")
118+
tmpDataPath, cleanup, err := temp.MkdirTemp("data")
119119
if err != nil {
120120
testlogger.Fatalf("Unable to create temporary data path %v\n", err)
121121
}
122+
defer cleanup()
122123

123124
setting.CustomPath = filepath.Join(setting.AppWorkPath, "custom")
124125
setting.AppDataPath = tmpDataPath
@@ -135,8 +136,5 @@ func MainTest(m *testing.M) {
135136
if err := removeAllWithRetry(setting.RepoRootPath); err != nil {
136137
fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
137138
}
138-
if err := removeAllWithRetry(tmpDataPath); err != nil {
139-
fmt.Fprintf(os.Stderr, "os.RemoveAll: %v\n", err)
140-
}
141139
os.Exit(exitStatus)
142140
}

models/unittest/testdb.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,19 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
9393
setting.SSH.Domain = "try.gitea.io"
9494
setting.Database.Type = "sqlite3"
9595
setting.Repository.DefaultBranch = "master" // many test code still assume that default branch is called "master"
96-
repoRootPath, _, err := temp.MkdirTemp("repos")
96+
repoRootPath, cleanup1, err := temp.MkdirTemp("repos")
9797
if err != nil {
9898
fatalTestError("TempDir: %v\n", err)
9999
}
100+
defer cleanup1()
101+
100102
setting.RepoRootPath = repoRootPath
101-
appDataPath, _, err := temp.MkdirTemp("appdata")
103+
appDataPath, cleanup2, err := temp.MkdirTemp("appdata")
102104
if err != nil {
103105
fatalTestError("TempDir: %v\n", err)
104106
}
107+
defer cleanup2()
108+
105109
setting.AppDataPath = appDataPath
106110
setting.AppWorkPath = giteaRoot
107111
setting.StaticRootPath = giteaRoot
@@ -154,13 +158,6 @@ func MainTest(m *testing.M, testOptsArg ...*TestOptions) {
154158
fatalTestError("tear down failed: %v\n", err)
155159
}
156160
}
157-
158-
if err = util.RemoveAll(repoRootPath); err != nil {
159-
fatalTestError("util.RemoveAll: %v\n", err)
160-
}
161-
if err = util.RemoveAll(appDataPath); err != nil {
162-
fatalTestError("util.RemoveAll: %v\n", err)
163-
}
164161
os.Exit(exitStatus)
165162
}
166163

0 commit comments

Comments
 (0)