mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-03 18:24:29 +00:00
9dc04289aa
before: gitrepo vs git packages after: git package fully handle all git operations by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide path details. benefits: 1. remove all unnecessary wrappers, developers no need to struggle with "which package should be used" 2. simplify code, RepositoryFacade can (will) be used everywhere, all "path" details are (will be) hidden
32 lines
969 B
Go
32 lines
969 B
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package repo
|
|
|
|
import (
|
|
"testing"
|
|
|
|
repo_model "gitea.dev/models/repo"
|
|
"gitea.dev/models/unittest"
|
|
"gitea.dev/modules/git"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestEditorUtils(t *testing.T) {
|
|
unittest.PrepareTestEnv(t)
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
t.Run("getUniquePatchBranchName", func(t *testing.T) {
|
|
branchName := getUniquePatchBranchName(t.Context(), "user2", repo)
|
|
assert.Equal(t, "user2-patch-1", branchName)
|
|
})
|
|
t.Run("getClosestParentWithFiles", func(t *testing.T) {
|
|
gitRepo, _ := git.OpenRepository(repo)
|
|
defer gitRepo.Close()
|
|
treePath := getClosestParentWithFiles(t.Context(), gitRepo, "sub-home-md-img-check", "docs/foo/bar")
|
|
assert.Equal(t, "docs", treePath)
|
|
treePath = getClosestParentWithFiles(t.Context(), gitRepo, "sub-home-md-img-check", "any/other")
|
|
assert.Empty(t, treePath)
|
|
})
|
|
}
|