Skip to content

Remove hardcoded paths to fix randomly failing tests #3347

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

Merged
merged 2 commits into from
Jan 10, 2018
Merged
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
1 change: 1 addition & 0 deletions integrations/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func prepareTestEnv(t testing.TB) {
assert.NoError(t, models.LoadFixtures())
assert.NoError(t, os.RemoveAll(setting.RepoRootPath))
assert.NoError(t, os.RemoveAll(models.LocalCopyPath()))
assert.NoError(t, os.RemoveAll(models.LocalUncycloPath()))

assert.NoError(t, com.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
setting.RepoRootPath))
Expand Down
1 change: 1 addition & 0 deletions integrations/mysql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ROOT = integrations/gitea-integration-mysql/gitea-repositories

[repository.local]
LOCAL_COPY_PATH = tmp/local-repo-mysql
LOCAL_WIKI_PATH = tmp/local-wiki-mysql

[server]
SSH_DOMAIN = localhost
Expand Down
1 change: 1 addition & 0 deletions integrations/pgsql.ini.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ROOT = integrations/gitea-integration-pgsql/gitea-repositories

[repository.local]
LOCAL_COPY_PATH = tmp/local-repo-pgsql
LOCAL_WIKI_PATH = tmp/local-wiki-pgsql

[server]
SSH_DOMAIN = localhost
Expand Down
2 changes: 2 additions & 0 deletions integrations/sqlite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ ROOT = integrations/gitea-integration-sqlite/gitea-repositories

[repository.local]
LOCAL_COPY_PATH = tmp/local-repo-sqlite
LOCAL_WIKI_PATH = tmp/local-wiki-sqlite

[server]
SSH_DOMAIN = localhost
Expand All @@ -23,6 +24,7 @@ ROOT_URL = http://localhost:3003/
DISABLE_SSH = false
SSH_PORT = 22
LFS_START_SERVER = true
LFS_CONTENT_PATH = data/lfs-sqlite
OFFLINE_MODE = false
LFS_JWT_SECRET = Tv_MjmZuHqpIY6GFl12ebgkRAMt4RlWt0v4EHKSXO0w

Expand Down
2 changes: 1 addition & 1 deletion models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
}

// Clone base repo.
tmpBasePath := path.Join(setting.AppDataPath, "tmp/repos", com.ToStr(time.Now().Nanosecond())+".git")
tmpBasePath := path.Join(LocalCopyPath(), "merge-"+com.ToStr(time.Now().Nanosecond())+".git")

if err := os.MkdirAll(path.Dir(tmpBasePath), os.ModePerm); err != nil {
return fmt.Errorf("Failed to create dir %s: %v", tmpBasePath, err)
Expand Down
10 changes: 9 additions & 1 deletion models/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,17 @@ func (repo *Repository) InitUncyclo() error {
return nil
}

// LocalUncycloPath returns the local wiki repository copy path.
func LocalUncycloPath() string {
if filepath.IsAbs(setting.Repository.Local.LocalUncycloPath) {
return setting.Repository.Local.LocalUncycloPath
}
return path.Join(setting.AppDataPath, setting.Repository.Local.LocalUncycloPath)
}

// LocalUncycloPath returns the path to the local wiki repository (?).
func (repo *Repository) LocalUncycloPath() string {
return path.Join(setting.AppDataPath, "tmp/local-wiki", com.ToStr(repo.ID))
return path.Join(LocalUncycloPath(), com.ToStr(repo.ID))
}

// UpdateLocalUncyclo makes sure the local copy of repository wiki is up-to-date.
Expand Down
2 changes: 1 addition & 1 deletion models/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestRepository_InitUncyclo(t *testing.T) {
func TestRepository_LocalUncycloPath(t *testing.T) {
PrepareTestEnv(t)
repo := AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
expected := filepath.Join(setting.AppDataPath, "tmp/local-wiki/1")
expected := filepath.Join(setting.AppDataPath, setting.Repository.Local.LocalUncycloPath, "1")
assert.Equal(t, expected, repo.LocalUncycloPath())
}

Expand Down
3 changes: 3 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ var (
// Repository local settings
Local struct {
LocalCopyPath string
LocalUncycloPath string
} `ini:"-"`
}{
AnsiCharset: "",
Expand Down Expand Up @@ -254,8 +255,10 @@ var (
// Repository local settings
Local: struct {
LocalCopyPath string
LocalUncycloPath string
}{
LocalCopyPath: "tmp/local-repo",
LocalUncycloPath: "tmp/local-wiki",
},
}
RepoRootPath string
Expand Down