Files

32 lines
994 B
Go
Raw Permalink Normal View History

2018-12-21 10:32:11 +08:00
// Copyright 2018 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
2018-12-21 10:32:11 +08:00
package repo
import (
"testing"
2025-06-21 19:20:51 +08:00
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/gitrepo"
2018-12-21 10:32:11 +08:00
"github.com/stretchr/testify/assert"
)
2025-06-21 19:20:51 +08:00
func TestEditorUtils(t *testing.T) {
unittest.PrepareTestEnv(t)
2025-06-21 19:20:51 +08:00
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) {
2025-08-28 00:31:21 +08:00
gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo)
2025-06-21 19:20:51 +08:00
defer gitRepo.Close()
treePath := getClosestParentWithFiles(gitRepo, "sub-home-md-img-check", "docs/foo/bar")
assert.Equal(t, "docs", treePath)
treePath = getClosestParentWithFiles(gitRepo, "sub-home-md-img-check", "any/other")
assert.Empty(t, treePath)
})
}