Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sqlite supports memory database for test purpose #32610

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ SWAGGER_SPEC_S_JSON := s|"basePath": *"{{AppSubUrl \| JSEscape}}/api/v1"|"basePa
SWAGGER_EXCLUDE := code.gitea.io/sdk
SWAGGER_NEWLINE_COMMAND := -e '$$a\'

TEST_SQLITE_PATH ?= :memory:
TEST_MYSQL_HOST ?= mysql:3306
TEST_MYSQL_DBNAME ?= testgitea
TEST_MYSQL_USERNAME ?= root
Expand Down Expand Up @@ -532,7 +533,8 @@ $(GO_LICENSE_FILE): go.mod go.sum
@rm -rf $(GO_LICENSE_TMP_DIR)

generate-ini-sqlite:
sed -e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
sed -e 's|{{TEST_SQLITE_PATH}}|${TEST_SQLITE_PATH}|g' \
-e 's|{{REPO_TEST_DIR}}|${REPO_TEST_DIR}|g' \
-e 's|{{TEST_LOGGER}}|$(or $(TEST_LOGGER),test$(COMMA)file)|g' \
-e 's|{{TEST_TYPE}}|$(or $(TEST_TYPE),integration)|g' \
tests/sqlite.ini.tmpl > tests/sqlite.ini
Expand Down
6 changes: 4 additions & 2 deletions modules/setting/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ func DBConnStr() (string, error) {
if !EnableSQLite3 {
return "", errors.New("this Gitea binary was not built with SQLite3 support")
}
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
return "", fmt.Errorf("Failed to create directories: %w", err)
if Database.Path != ":memory:" {
if err := os.MkdirAll(filepath.Dir(Database.Path), os.ModePerm); err != nil {
return "", fmt.Errorf("failed to create directories: %w", err)
}
}
journalMode := ""
if Database.SQLiteJournalMode != "" {
Expand Down
2 changes: 1 addition & 1 deletion tests/sqlite.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ RUN_MODE = prod

[database]
DB_TYPE = sqlite3
PATH = tests/{{TEST_TYPE}}/gitea-{{TEST_TYPE}}-sqlite/gitea.db
PATH = {{TEST_SQLITE_PATH}}

[indexer]
REPO_INDEXER_ENABLED = true
Expand Down
Loading