本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

51 lines
1.2KB

  1. // Copyright 2018 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package git
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestRepository_GetRefs(t *testing.T) {
  11. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  12. bareRepo1, err := OpenRepository(bareRepo1Path)
  13. assert.NoError(t, err)
  14. refs, err := bareRepo1.GetRefs()
  15. assert.NoError(t, err)
  16. assert.Len(t, refs, 5)
  17. expectedRefs := []string{
  18. BranchPrefix + "branch1",
  19. BranchPrefix + "branch2",
  20. BranchPrefix + "master",
  21. TagPrefix + "test",
  22. NotesRef,
  23. }
  24. for _, ref := range refs {
  25. assert.Contains(t, expectedRefs, ref.Name)
  26. }
  27. }
  28. func TestRepository_GetRefsFiltered(t *testing.T) {
  29. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  30. bareRepo1, err := OpenRepository(bareRepo1Path)
  31. assert.NoError(t, err)
  32. refs, err := bareRepo1.GetRefsFiltered(TagPrefix)
  33. assert.NoError(t, err)
  34. if assert.Len(t, refs, 1) {
  35. assert.Equal(t, TagPrefix+"test", refs[0].Name)
  36. assert.Equal(t, "tag", refs[0].Type)
  37. assert.Equal(t, "3ad28a9149a2864384548f3d17ed7f38014c9e8a", refs[0].Object.String())
  38. }
  39. }
上海开阖软件有限公司 沪ICP备12045867号-1