aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/commit_info_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'modules/git/commit_info_test.go')
-rw-r--r--modules/git/commit_info_test.go25
1 files changed, 21 insertions, 4 deletions
diff --git a/modules/git/commit_info_test.go b/modules/git/commit_info_test.go
index 1e331fac00..078b6815d2 100644
--- a/modules/git/commit_info_test.go
+++ b/modules/git/commit_info_test.go
@@ -4,12 +4,12 @@
package git
import (
- "context"
"path/filepath"
"testing"
"time"
"github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
)
const (
@@ -83,7 +83,7 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
}
// FIXME: Context.TODO() - if graceful has started we should use its Shutdown context otherwise use install signals in TestMain.
- commitsInfo, treeCommit, err := entries.GetCommitsInfo(context.TODO(), commit, testCase.Path)
+ commitsInfo, treeCommit, err := entries.GetCommitsInfo(t.Context(), "/any/repo-link", commit, testCase.Path)
assert.NoError(t, err, "Unable to get commit information for entries of subtree: %s in commit: %s from testcase due to error: %v", testCase.Path, testCase.CommitID, err)
if err != nil {
t.FailNow()
@@ -121,6 +121,23 @@ func TestEntries_GetCommitsInfo(t *testing.T) {
defer clonedRepo1.Close()
testGetCommitsInfo(t, clonedRepo1)
+
+ t.Run("NonExistingSubmoduleAsNil", func(t *testing.T) {
+ commit, err := bareRepo1.GetCommit("HEAD")
+ require.NoError(t, err)
+ treeEntry, err := commit.GetTreeEntryByPath("file1.txt")
+ require.NoError(t, err)
+ cisf, err := GetCommitInfoSubmoduleFile("/any/repo-link", "file1.txt", commit, treeEntry.ID)
+ require.NoError(t, err)
+ assert.Equal(t, &CommitSubmoduleFile{
+ repoLink: "/any/repo-link",
+ fullPath: "file1.txt",
+ refURL: "",
+ refID: "e2129701f1a4d54dc44f03c93bca0a2aec7c5449",
+ }, cisf)
+ // since there is no refURL, it means that the submodule info doesn't exist, so it won't have a web link
+ assert.Nil(t, cisf.SubmoduleWebLinkTree(t.Context()))
+ })
}
func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
@@ -159,8 +176,8 @@ func BenchmarkEntries_GetCommitsInfo(b *testing.B) {
entries.Sort()
b.ResetTimer()
b.Run(benchmark.name, func(b *testing.B) {
- for i := 0; i < b.N; i++ {
- _, _, err := entries.GetCommitsInfo(context.Background(), commit, "")
+ for b.Loop() {
+ _, _, err := entries.GetCommitsInfo(b.Context(), "/any/repo-link", commit, "")
if err != nil {
b.Fatal(err)
}