Skip to content

Commit 38fdab9

Browse files
committed
test: integration add git cli big file commit
1 parent 7fcdd75 commit 38fdab9

File tree

1 file changed

+89
-85
lines changed

1 file changed

+89
-85
lines changed

integrations/git_test.go

Lines changed: 89 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ import (
2626
"github.com/stretchr/testify/assert"
2727
)
2828

29+
const (
30+
littleSize = 1024 //1ko
31+
bigSize = 128 * 1024 * 1024 //128Mo
32+
)
33+
2934
func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
3035
prepareTestEnv(t)
3136
s := http.Server{
@@ -49,44 +54,6 @@ func onGiteaRun(t *testing.T, callback func(*testing.T, *url.URL)) {
4954
callback(t, u)
5055
}
5156

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-
9057
func TestGit(t *testing.T) {
9158
onGiteaRun(t, func(t *testing.T, u *url.URL) {
9259
u.Path = "user2/repo1.git"
@@ -128,15 +95,12 @@ func TestGit(t *testing.T) {
12895
})
12996

13097
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)
138103
})
139-
assert.NoError(t, err)
140104
})
141105
})
142106
t.Run("LFS", func(t *testing.T) {
@@ -149,27 +113,15 @@ func TestGit(t *testing.T) {
149113
err = git.AddChanges(dstPath, false, ".gitattributes")
150114
assert.NoError(t, err)
151115

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)
159121
})
160-
assert.NoError(t, err)
161122
})
162123
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)
173125
})
174126
})
175127
})
@@ -235,11 +187,12 @@ func TestGit(t *testing.T) {
235187
})
236188
//time.Sleep(5 * time.Minute)
237189
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+
})
243196
})
244197
})
245198
t.Run("LFS", func(t *testing.T) {
@@ -254,26 +207,77 @@ func TestGit(t *testing.T) {
254207
err = git.AddChanges(dstPath, false, ".gitattributes")
255208
assert.NoError(t, err)
256209

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+
})
261216
})
217+
/* Failed without #3152. TODO activate with fix.
262218
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)
273220
})
221+
*/
274222
})
275-
//TODO ADD big file to LFS tests for validating #2930
276-
277223
})
278224
})
279225
}
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

Comments
 (0)