You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_branch_test.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_GetBranches(t *testing.T) {
  11. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  12. bareRepo1, err := OpenRepository(bareRepo1Path)
  13. assert.NoError(t, err)
  14. defer bareRepo1.Close()
  15. branches, countAll, err := bareRepo1.GetBranches(0, 2)
  16. assert.NoError(t, err)
  17. assert.Len(t, branches, 2)
  18. assert.EqualValues(t, 3, countAll)
  19. assert.ElementsMatch(t, []string{"branch1", "branch2"}, branches)
  20. branches, countAll, err = bareRepo1.GetBranches(0, 0)
  21. assert.NoError(t, err)
  22. assert.Len(t, branches, 3)
  23. assert.EqualValues(t, 3, countAll)
  24. assert.ElementsMatch(t, []string{"branch1", "branch2", "master"}, branches)
  25. branches, countAll, err = bareRepo1.GetBranches(5, 1)
  26. assert.NoError(t, err)
  27. assert.Len(t, branches, 0)
  28. assert.EqualValues(t, 3, countAll)
  29. assert.ElementsMatch(t, []string{}, branches)
  30. }
  31. func BenchmarkRepository_GetBranches(b *testing.B) {
  32. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  33. bareRepo1, err := OpenRepository(bareRepo1Path)
  34. if err != nil {
  35. b.Fatal(err)
  36. }
  37. defer bareRepo1.Close()
  38. for i := 0; i < b.N; i++ {
  39. _, _, err := bareRepo1.GetBranches(0, 0)
  40. if err != nil {
  41. b.Fatal(err)
  42. }
  43. }
  44. }