gitea源码

1234567891011121314151617181920212223242526272829303132
  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "testing"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/models/unittest"
  8. "code.gitea.io/gitea/modules/gitrepo"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func TestEditorUtils(t *testing.T) {
  12. unittest.PrepareTestEnv(t)
  13. repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
  14. t.Run("getUniquePatchBranchName", func(t *testing.T) {
  15. branchName := getUniquePatchBranchName(t.Context(), "user2", repo)
  16. assert.Equal(t, "user2-patch-1", branchName)
  17. })
  18. t.Run("getClosestParentWithFiles", func(t *testing.T) {
  19. gitRepo, _ := gitrepo.OpenRepository(t.Context(), repo)
  20. defer gitRepo.Close()
  21. treePath := getClosestParentWithFiles(gitRepo, "sub-home-md-img-check", "docs/foo/bar")
  22. assert.Equal(t, "docs", treePath)
  23. treePath = getClosestParentWithFiles(gitRepo, "sub-home-md-img-check", "any/other")
  24. assert.Empty(t, treePath)
  25. })
  26. }