Skip to content

Commit d01ca3a

Browse files
committed
fine tune tests for markup (which requires git module)
1 parent db0d7a1 commit d01ca3a

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

modules/git/git.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"fmt"
1111
"os"
1212
"os/exec"
13-
"path/filepath"
1413
"runtime"
1514
"strings"
1615
"sync"
@@ -143,12 +142,8 @@ func InitSimple(ctx context.Context) error {
143142
// HomeDir is the home dir for git to store the global config file used by Gitea internally
144143
func HomeDir() string {
145144
if setting.RepoRootPath == "" {
146-
// TODO: now, some unit test code call the git module directly without initialization, which is incorrect.
147-
// at the moment, we just use a temp HomeDir to prevent from conflicting with user's git config
148-
// in the future, the git module should be initialized first before use.
149-
tmpHomeDir := filepath.Join(os.TempDir(), "gitea-temp-home")
150-
log.Error("Git's HomeDir is empty (RepoRootPath is empty), the git module is not initialized correctly, using a temp HomeDir (%s) temporarily", tmpHomeDir)
151-
return tmpHomeDir
145+
log.Fatal("Can not get Git's HomeDir (RepoRootPath is empty), the setting and git modules are not initialized correctly")
146+
return ""
152147
}
153148
return setting.RepoRootPath
154149
}

modules/markup/html_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
package markup_test
66

77
import (
8+
"context"
89
"io"
910
"strings"
1011
"testing"
1112

1213
"code.gitea.io/gitea/modules/emoji"
1314
"code.gitea.io/gitea/modules/git"
15+
"code.gitea.io/gitea/modules/log"
1416
. "code.gitea.io/gitea/modules/markup"
1517
"code.gitea.io/gitea/modules/markup/markdown"
1618
"code.gitea.io/gitea/modules/setting"
@@ -25,6 +27,13 @@ var localMetas = map[string]string{
2527
"repoPath": "../../integrations/gitea-repositories-meta/user13/repo11.git/",
2628
}
2729

30+
func TestMain(m *testing.M) {
31+
setting.LoadAllowEmpty()
32+
if err := git.InitSimple(context.Background()); err != nil {
33+
log.Fatal("git init failed, err: %v", err)
34+
}
35+
}
36+
2837
func TestRender_Commits(t *testing.T) {
2938
setting.AppURL = TestAppURL
3039
test := func(input, expected string) {

modules/markup/markdown/markdown_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package markdown_test
66

77
import (
8+
"context"
89
"strings"
910
"testing"
1011

@@ -31,6 +32,13 @@ var localMetas = map[string]string{
3132
"repoPath": "../../../integrations/gitea-repositories-meta/user13/repo11.git/",
3233
}
3334

35+
func TestMain(m *testing.M) {
36+
setting.LoadAllowEmpty()
37+
if err := git.InitSimple(context.Background()); err != nil {
38+
log.Fatal("git init failed, err: %v", err)
39+
}
40+
}
41+
3442
func TestRender_StandardLinks(t *testing.T) {
3543
setting.AppURL = AppURL
3644
setting.AppSubURL = AppSubURL

0 commit comments

Comments
 (0)