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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. assert.NoError(t, err)
  38. commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
  39. assert.NoError(t, err)
  40. assert.NotNil(t, commit)
  41. assert.NotNil(t, commit.Signature)
  42. // test that signature is not in message
  43. assert.Equal(t, "tag", commit.CommitMessage)
  44. }
  45. func TestGetCommitWithBadCommitID(t *testing.T) {
  46. bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
  47. bareRepo1, err := OpenRepository(bareRepo1Path)
  48. assert.NoError(t, err)
  49. commit, err := bareRepo1.GetCommit("bad_branch")
  50. assert.Nil(t, commit)
  51. assert.Error(t, err)
  52. assert.True(t, IsErrNotExist(err))
  53. }