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_commit_test.go 2.0KB

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