@@ -26,6 +26,11 @@ import (
26
26
"github.com/stretchr/testify/assert"
27
27
)
28
28
29
+ const (
30
+ littleSize = 1024 //1ko
31
+ bigSize = 128 * 1024 * 1024 //128Mo
32
+ )
33
+
29
34
func onGiteaRun (t * testing.T , callback func (* testing.T , * url.URL )) {
30
35
prepareTestEnv (t )
31
36
s := http.Server {
@@ -49,44 +54,6 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
49
54
callback (t , u )
50
55
}
51
56
52
- func generateCommitWithNewData (repoPath , email , fullName string ) error {
53
- //Generate random file
54
- data := make ([]byte , 1024 )
55
- _ , err := rand .Read (data )
56
- if err != nil {
57
- return err
58
- }
59
- tmpFile , err := ioutil .TempFile (repoPath , "data-file-" )
60
- if err != nil {
61
- return err
62
- }
63
- defer tmpFile .Close ()
64
- _ , err = tmpFile .Write (data )
65
- if err != nil {
66
- return err
67
- }
68
-
69
- //Commit
70
- err = git .AddChanges (repoPath , false , filepath .Base (tmpFile .Name ()))
71
- if err != nil {
72
- return err
73
- }
74
- err = git .CommitChanges (repoPath , git.CommitChangesOptions {
75
- Committer : & git.Signature {
76
- Email : email ,
77
- Name : fullName ,
78
- When : time .Now (),
79
- },
80
- Author : & git.Signature {
81
- Email : email ,
82
- Name : fullName ,
83
- When : time .Now (),
84
- },
85
- Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
86
- })
87
- return err
88
- }
89
-
90
57
func TestGit (t * testing.T ) {
91
58
onGiteaRun (t , func (t * testing.T , u * url.URL ) {
92
59
u .Path = "user2/repo1.git"
@@ -128,15 +95,12 @@ func TestGit(t *testing.T) {
128
95
})
129
96
130
97
t .Run ("PushCommit" , func (t * testing.T ) {
131
- err = generateCommitWithNewData (
dstPath ,
"[email protected] " ,
"User Two" )
132
- assert .NoError (t , err )
133
- //Push
134
- err = git .Push (dstPath , git.PushOptions {
135
- Branch : "master" ,
136
- Remote : u .String (),
137
- Force : false ,
98
+ t .Run ("Little" , func (t * testing.T ) {
99
+ commitAndPush (t , littleSize , dstPath )
100
+ })
101
+ t .Run ("Big" , func (t * testing.T ) {
102
+ commitAndPush (t , bigSize , dstPath )
138
103
})
139
- assert .NoError (t , err )
140
104
})
141
105
})
142
106
t .Run ("LFS" , func (t * testing.T ) {
@@ -149,27 +113,15 @@ func TestGit(t *testing.T) {
149
113
err = git .AddChanges (dstPath , false , ".gitattributes" )
150
114
assert .NoError (t , err )
151
115
152
- err = generateCommitWithNewData (
dstPath ,
"[email protected] " ,
"User Two" )
153
- //Push
154
- u .User = url .UserPassword ("user2" , userPassword )
155
- err = git .Push (dstPath , git.PushOptions {
156
- Branch : "master" ,
157
- Remote : u .String (),
158
- Force : false ,
116
+ t .Run ("Little" , func (t * testing.T ) {
117
+ commitAndPush (t , littleSize , dstPath )
118
+ })
119
+ t .Run ("Big" , func (t * testing.T ) {
120
+ commitAndPush (t , bigSize , dstPath )
159
121
})
160
- assert .NoError (t , err )
161
122
})
162
123
t .Run ("Locks" , func (t * testing.T ) {
163
- _ , err = git .NewCommand ("remote" ).AddArguments ("set-url" , "origin" , u .String ()).RunInDir (dstPath ) //TODO add test ssh git-lfs-creds
164
- assert .NoError (t , err )
165
- _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (dstPath )
166
- assert .NoError (t , err )
167
- _ , err = git .NewCommand ("lfs" ).AddArguments ("lock" , "README.md" ).RunInDir (dstPath )
168
- assert .NoError (t , err )
169
- _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (dstPath )
170
- assert .NoError (t , err )
171
- _ , err = git .NewCommand ("lfs" ).AddArguments ("unlock" , "README.md" ).RunInDir (dstPath )
172
- assert .NoError (t , err )
124
+ lockTest (t , u .String (), dstPath )
173
125
})
174
126
})
175
127
})
@@ -235,11 +187,12 @@ func TestGit(t *testing.T) {
235
187
})
236
188
//time.Sleep(5 * time.Minute)
237
189
t .Run ("PushCommit" , func (t * testing.T ) {
238
- err = generateCommitWithNewData (
dstPath ,
"[email protected] " ,
"User Two" )
239
- assert .NoError (t , err )
240
- //Push
241
- _ , err = git .NewCommand ("push" ).RunInDir (dstPath )
242
- assert .NoError (t , err )
190
+ t .Run ("Little" , func (t * testing.T ) {
191
+ commitAndPush (t , littleSize , dstPath )
192
+ })
193
+ t .Run ("Big" , func (t * testing.T ) {
194
+ commitAndPush (t , bigSize , dstPath )
195
+ })
243
196
})
244
197
})
245
198
t .Run ("LFS" , func (t * testing.T ) {
@@ -254,26 +207,77 @@ func TestGit(t *testing.T) {
254
207
err = git .AddChanges (dstPath , false , ".gitattributes" )
255
208
assert .NoError (t , err )
256
209
257
- err = generateCommitWithNewData (
dstPath ,
"[email protected] " ,
"User Two" )
258
- //Push
259
- _ , err = git .NewCommand ("push" ).RunInDir (dstPath )
260
- assert .NoError (t , err )
210
+ t .Run ("Little" , func (t * testing.T ) {
211
+ commitAndPush (t , littleSize , dstPath )
212
+ })
213
+ t .Run ("Big" , func (t * testing.T ) {
214
+ commitAndPush (t , bigSize , dstPath )
215
+ })
261
216
})
217
+ /* Failed without #3152. TODO activate with fix.
262
218
t.Run("Locks", func(t *testing.T) {
263
- _ , err = git .NewCommand ("remote" ).AddArguments ("set-url" , "origin" , u .String ()).RunInDir (dstPath ) //TODO add test ssh git-lfs-creds
264
- assert .NoError (t , err )
265
- _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (dstPath )
266
- assert .NoError (t , err )
267
- _ , err = git .NewCommand ("lfs" ).AddArguments ("lock" , "README.md" ).RunInDir (dstPath )
268
- assert .NoError (t , err )
269
- _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (dstPath )
270
- assert .NoError (t , err )
271
- _ , err = git .NewCommand ("lfs" ).AddArguments ("unlock" , "README.md" ).RunInDir (dstPath )
272
- assert .NoError (t , err )
219
+ lockTest(t, u.String(), dstPath)
273
220
})
221
+ */
274
222
})
275
- //TODO ADD big file to LFS tests for validating #2930
276
-
277
223
})
278
224
})
279
225
}
226
+
227
+ func lockTest (t * testing.T , remote , repoPath string ) {
228
+ _ , err := git .NewCommand ("remote" ).AddArguments ("set-url" , "origin" , remote ).RunInDir (repoPath ) //TODO add test ssh git-lfs-creds
229
+ assert .NoError (t , err )
230
+ _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (repoPath )
231
+ assert .NoError (t , err )
232
+ _ , err = git .NewCommand ("lfs" ).AddArguments ("lock" , "README.md" ).RunInDir (repoPath )
233
+ assert .NoError (t , err )
234
+ _ , err = git .NewCommand ("lfs" ).AddArguments ("locks" ).RunInDir (repoPath )
235
+ assert .NoError (t , err )
236
+ _ , err = git .NewCommand ("lfs" ).AddArguments ("unlock" , "README.md" ).RunInDir (repoPath )
237
+ assert .NoError (t , err )
238
+ }
239
+
240
+ func commitAndPush (t * testing.T , size int , repoPath string ) {
241
+ err := generateCommitWithNewData (
size ,
repoPath ,
"[email protected] " ,
"User Two" )
242
+ assert .NoError (t , err )
243
+ _ , err = git .NewCommand ("push" ).RunInDir (repoPath ) //Push
244
+ assert .NoError (t , err )
245
+ }
246
+
247
+ func generateCommitWithNewData (size int , repoPath , email , fullName string ) error {
248
+ //Generate random file
249
+ data := make ([]byte , size )
250
+ _ , err := rand .Read (data )
251
+ if err != nil {
252
+ return err
253
+ }
254
+ tmpFile , err := ioutil .TempFile (repoPath , "data-file-" )
255
+ if err != nil {
256
+ return err
257
+ }
258
+ defer tmpFile .Close ()
259
+ _ , err = tmpFile .Write (data )
260
+ if err != nil {
261
+ return err
262
+ }
263
+
264
+ //Commit
265
+ err = git .AddChanges (repoPath , false , filepath .Base (tmpFile .Name ()))
266
+ if err != nil {
267
+ return err
268
+ }
269
+ err = git .CommitChanges (repoPath , git.CommitChangesOptions {
270
+ Committer : & git.Signature {
271
+ Email : email ,
272
+ Name : fullName ,
273
+ When : time .Now (),
274
+ },
275
+ Author : & git.Signature {
276
+ Email : email ,
277
+ Name : fullName ,
278
+ When : time .Now (),
279
+ },
280
+ Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
281
+ })
282
+ return err
283
+ }
0 commit comments