mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-22 08:42:32 -05:00
d578b71d61
* move code.gitea.io/git to code.gitea.io/gitea/modules/git * fix imports * fix fmt * fix misspell * remove wrong tests data * fix unit tests * fix tests * fix tests * fix tests * fix tests * fix tests * enable Debug to trace the failure tests * fix tests * fix tests * fix tests * fix tests * fix tests * comment commit count tests since git clone depth is 50 * fix tests * update from code.gitea.io/git * revert change to makefile
59 lines
2 KiB
Go
59 lines
2 KiB
Go
// Copyright 2018 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package git
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestRepository_GetCommitBranches(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
assert.NoError(t, err)
|
|
|
|
// these test case are specific to the repo1_bare test repo
|
|
testCases := []struct {
|
|
CommitID string
|
|
ExpectedBranches []string
|
|
}{
|
|
{"2839944139e0de9737a044f78b0e4b40d989a9e3", []string{"branch1"}},
|
|
{"5c80b0245c1c6f8343fa418ec374b13b5d4ee658", []string{"branch2"}},
|
|
{"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}},
|
|
{"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}},
|
|
{"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}},
|
|
{"master", []string{"master"}},
|
|
}
|
|
for _, testCase := range testCases {
|
|
commit, err := bareRepo1.GetCommit(testCase.CommitID)
|
|
assert.NoError(t, err)
|
|
branches, err := bareRepo1.getBranches(commit, 2)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, testCase.ExpectedBranches, branches)
|
|
}
|
|
}
|
|
|
|
func TestGetTagCommitWithSignature(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
commit, err := bareRepo1.GetCommit("3ad28a9149a2864384548f3d17ed7f38014c9e8a")
|
|
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, commit)
|
|
assert.NotNil(t, commit.Signature)
|
|
// test that signature is not in message
|
|
assert.Equal(t, "tag", commit.CommitMessage)
|
|
}
|
|
|
|
func TestGetCommitWithBadCommitID(t *testing.T) {
|
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
|
commit, err := bareRepo1.GetCommit("bad_branch")
|
|
assert.Nil(t, commit)
|
|
assert.Error(t, err)
|
|
assert.EqualError(t, err, "object does not exist [id: bad_branch, rel_path: ]")
|
|
}
|