88 "testing"
99 "time"
1010
11+ "code.gitea.io/gitea/modules/test"
1112 "github.com/stretchr/testify/assert"
1213 "github.com/stretchr/testify/require"
1314)
@@ -30,28 +31,57 @@ func cloneRepo(tb testing.TB, url string) (string, error) {
3031}
3132
3233func testGetCommitsInfo (t * testing.T , repo1 * Repository ) {
34+ type expectedEntryInfo struct {
35+ CommitID string
36+ Size int64
37+ }
38+
3339 // these test case are specific to the repo1 test repo
3440 testCases := []struct {
3541 CommitID string
3642 Path string
37- ExpectedIDs map [string ]string
43+ ExpectedIDs map [string ]expectedEntryInfo
3844 ExpectedTreeCommit string
3945 }{
40- {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" , "" , map [string ]string {
41- "file1.txt" : "95bb4d39648ee7e325106df01a621c530863a653" ,
42- "file2.txt" : "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" ,
46+ {"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" , "" , map [string ]expectedEntryInfo {
47+ "file1.txt" : {
48+ CommitID : "95bb4d39648ee7e325106df01a621c530863a653" ,
49+ Size : 6 ,
50+ },
51+ "file2.txt" : {
52+ CommitID : "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" ,
53+ Size : 6 ,
54+ },
4355 }, "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" },
44- {"2839944139e0de9737a044f78b0e4b40d989a9e3" , "" , map [string ]string {
45- "file1.txt" : "2839944139e0de9737a044f78b0e4b40d989a9e3" ,
46- "branch1.txt" : "9c9aef8dd84e02bc7ec12641deb4c930a7c30185" ,
56+ {"2839944139e0de9737a044f78b0e4b40d989a9e3" , "" , map [string ]expectedEntryInfo {
57+ "file1.txt" : {
58+ CommitID : "2839944139e0de9737a044f78b0e4b40d989a9e3" ,
59+ Size : 15 ,
60+ },
61+ "branch1.txt" : {
62+ CommitID : "9c9aef8dd84e02bc7ec12641deb4c930a7c30185" ,
63+ Size : 8 ,
64+ },
4765 }, "2839944139e0de9737a044f78b0e4b40d989a9e3" },
48- {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658" , "branch2" , map [string ]string {
49- "branch2.txt" : "5c80b0245c1c6f8343fa418ec374b13b5d4ee658" ,
66+ {"5c80b0245c1c6f8343fa418ec374b13b5d4ee658" , "branch2" , map [string ]expectedEntryInfo {
67+ "branch2.txt" : {
68+ CommitID : "5c80b0245c1c6f8343fa418ec374b13b5d4ee658" ,
69+ Size : 8 ,
70+ },
5071 }, "5c80b0245c1c6f8343fa418ec374b13b5d4ee658" },
51- {"feaf4ba6bc635fec442f46ddd4512416ec43c2c2" , "" , map [string ]string {
52- "file1.txt" : "95bb4d39648ee7e325106df01a621c530863a653" ,
53- "file2.txt" : "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" ,
54- "foo" : "37991dec2c8e592043f47155ce4808d4580f9123" ,
72+ {"feaf4ba6bc635fec442f46ddd4512416ec43c2c2" , "" , map [string ]expectedEntryInfo {
73+ "file1.txt" : {
74+ CommitID : "95bb4d39648ee7e325106df01a621c530863a653" ,
75+ Size : 6 ,
76+ },
77+ "file2.txt" : {
78+ CommitID : "8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2" ,
79+ Size : 6 ,
80+ },
81+ "foo" : {
82+ CommitID : "37991dec2c8e592043f47155ce4808d4580f9123" ,
83+ Size : 0 ,
84+ },
5585 }, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2" },
5686 }
5787 for _ , testCase := range testCases {
@@ -93,16 +123,29 @@ func testGetCommitsInfo(t *testing.T, repo1 *Repository) {
93123 for _ , commitInfo := range commitsInfo {
94124 entry := commitInfo .Entry
95125 commit := commitInfo .Commit
96- expectedID , ok := testCase .ExpectedIDs [entry .Name ()]
126+ expectedInfo , ok := testCase .ExpectedIDs [entry .Name ()]
97127 if ! assert .True (t , ok ) {
98128 continue
99129 }
100- assert .Equal (t , expectedID , commit .ID .String ())
130+ assert .Equal (t , expectedInfo .CommitID , commit .ID .String ())
131+ assert .Equal (t , expectedInfo .Size , entry .Size (), entry .Name ())
101132 }
102133 }
103134}
104135
105- func TestEntries_GetCommitsInfo (t * testing.T ) {
136+ func TestEntries_GetCommitsInfo_Batch (t * testing.T ) {
137+ defer test .MockVariableValue (& DefaultFeatures ().SupportCatFileBatchCommand , false )()
138+
139+ testEntriesGetCommitsInfo (t )
140+ }
141+
142+ func TestEntries_GetCommitsInfo_BatchCommand (t * testing.T ) {
143+ defer test .MockVariableValue (& DefaultFeatures ().SupportCatFileBatchCommand , true )()
144+
145+ testEntriesGetCommitsInfo (t )
146+ }
147+
148+ func testEntriesGetCommitsInfo (t * testing.T ) {
106149 bareRepo1Path := filepath .Join (testReposDir , "repo1_bare" )
107150 bareRepo1 , err := OpenRepository (t .Context (), bareRepo1Path )
108151 assert .NoError (t , err )
0 commit comments