mirror of
https://github.com/go-gitea/gitea.git
synced 2025-08-04 16:21:17 +00:00
add test
This commit is contained in:
parent
be18643bfd
commit
68e5b28e7d
@ -4,6 +4,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@ -196,7 +197,7 @@ func TestParseDiffHunkString(t *testing.T) {
|
||||
}
|
||||
|
||||
func Test_GetAffectedHunksForTwoCommitsSpecialFile(t *testing.T) {
|
||||
repoPath := "./tests/repos/repo4_commitsbetween"
|
||||
repoPath := filepath.Join(testReposDir, "repo4_commitsbetween")
|
||||
hunks, err := GetAffectedHunksForTwoCommitsSpecialFile(t.Context(), repoPath, "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", "test.txt")
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, hunks, 1)
|
||||
|
@ -148,3 +148,26 @@ func TestCommitsByFileAndRange(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, commits, 1)
|
||||
}
|
||||
|
||||
func Test_CommitIDsBetween(t *testing.T) {
|
||||
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
|
||||
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
|
||||
require.NoError(t, err)
|
||||
defer bareRepo1.Close()
|
||||
|
||||
// Test with empty beforeCommitID
|
||||
commitIDs, err := CommitIDsBetween(bareRepo1.Ctx, bareRepo1.Path, "", "master")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, commitIDs, 7)
|
||||
assert.Equal(t, "ce064814f4a0d337b333e646ece456cd39fab612", commitIDs[0])
|
||||
assert.Equal(t, "95bb4d39648ee7e325106df01a621c530863a653", commitIDs[6])
|
||||
|
||||
// Test with a specific beforeCommitID
|
||||
commitIDs, err = CommitIDsBetween(bareRepo1.Ctx, bareRepo1.Path, "37991dec2c8e592043f47155ce4808d4580f9123", "master")
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, commitIDs, 2)
|
||||
assert.Equal(t, "ce064814f4a0d337b333e646ece456cd39fab612", commitIDs[0])
|
||||
assert.Equal(t, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2", commitIDs[1])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user