Some checks failed
cache-seeder / prune (push) Has been skipped
cache-seeder / frontend (push) Failing after 3s
cache-seeder / python (push) Failing after 3s
cache-seeder / gobuild (push) Failing after 4s
cache-seeder / lint (bindata, lint-backend) (push) Failing after 3s
giteabot backport / giteabot (push) Has been skipped
giteabot / giteabot (push) Has been skipped
cache-prune / prune (push) Has been skipped
release-nightly-snapcraft / build-and-publish (ubuntu-24.04) (push) Has been cancelled
release-nightly-snapcraft / build-and-publish (ubuntu-24.04-arm) (push) Has been cancelled
release-nightly / nightly-binary (push) Has been cancelled
release-nightly / nightly-container (push) Has been cancelled
cron-renovate / cron-renovate (push) Has been skipped
32 lines
982 B
Go
32 lines
982 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(t.Context(), 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)
|
|
})
|
|
}
|