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.

59 lines
2.0 KiB

  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_GetCommitBranches(t *testing.T) {
  11. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  12. bareRepo1, err := OpenRepository(bareRepo1Path)
  13. assert.NoError(t, err)
  14. // these test case are specific to the repo1_bare test repo
  15. testCases := []struct {
  16. CommitID string
  17. ExpectedBranches []string
  18. }{
  19. {"2839944139e0de9737a044f78b0e4b40d989a9e3", []string{"branch1"}},
  20. {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", []string{"branch2"}},
  21. {"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}},
  22. {"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}},
  23. {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}},
  24. {"master", []string{"master"}},
  25. }
  26. for _, testCase := range testCases {
  27. commit, err := bareRepo1.GetCommit(testCase.CommitID)
  28. assert.NoError(t, err)
  29. branches, err := bareRepo1.getBranches(commit, 2)
  30. assert.NoError(t, err)
  31. assert.Equal(t, testCase.ExpectedBranches, branches)
  32. }
  33. }
  34. func TestGetTagCommitWithSignature(t *testing.T) {
  35. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  36. bareRepo1, err := OpenRepository(bareRepo1Path)
  37. commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
  38. assert.NoError(t, err)
  39. assert.NotNil(t, commit)
  40. assert.NotNil(t, commit.Signature)
  41. // test that signature is not in message
  42. assert.Equal(t, "tag", commit.CommitMessage)
  43. }
  44. func TestGetCommitWithBadCommitID(t *testing.T) {
  45. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  46. bareRepo1, err := OpenRepository(bareRepo1Path)
  47. commit, err := bareRepo1.GetCommit("bad_branch")
  48. assert.Nil(t, commit)
  49. assert.Error(t, err)
  50. assert.EqualError(t, err, "object does not exist [id: bad_branch, rel_path: ]")
  51. }