Skip to content

Commit e0e3c43

Browse files
committed
sqlite supports memory database for test purpose
1 parent bc7d599 commit e0e3c43

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePa
170170
SWAGGER_EXCLUDE := code.gitea.io/sdk
171171
SWAGGER_NEWLINE_COMMAND := -e '$$a\'
172172

173+
TEST_SQLITE_PATH ?= :memory:
173174
TEST_MYSQL_HOST ?= mysql:3306
174175
TEST_MYSQL_DBNAME ?= testgitea
175176
TEST_MYSQL_USERNAME ?= root
@@ -532,7 +533,8 @@ $(GO_LICENSE_FILE): go.mod go.sum
532533
@rm -rf $(GO_LICENSE_TMP_DIR)
533534

534535
generate-ini-sqlite:
535-
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
536+
sed -e 's|{{TEST_SQLITE_PATH}}|${TEST_SQLITE_PATH}|g' \
537+
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
536538
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
537539
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
538540
tests/sqlite.ini.tmpl > tests/sqlite.ini

modules/setting/database.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ func DBConnStr() (string, error) {
119119
if !EnableSQLite3 {
120120
return "", errors.New("this Gitea binary was not built with SQLite3 support")
121121
}
122-
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
123-
return "", fmt.Errorf("Failed to create directories: %w", err)
122+
if Database.Path != ":memory:" && Database.Path != "" && Database.Path[0] != '/' {
123+
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
124+
return "", fmt.Errorf("Failed to create directories: %w", err)
125+
}
124126
}
125127
journalMode := ""
126128
if Database.SQLiteJournalMode != "" {

tests/sqlite.ini.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ RUN_MODE = prod
33

44
[database]
55
DB_TYPE = sqlite3
6-
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/gitea.db
6+
PATH = {{TEST_SQLITE_PATH}}
77

88
[indexer]
99
REPO_INDEXER_ENABLED = true

0 commit comments

Comments
 (0)