@@ -6,6 +6,7 @@ package integrations
6
6
7
7
import (
8
8
"context"
9
+ "fmt"
9
10
"io/ioutil"
10
11
"math/rand"
11
12
"net"
@@ -45,6 +46,44 @@ func onGiteaWebRun(t *testing.T, callback func(*testing.T, *url.URL)) {
45
46
callback (t , u )
46
47
}
47
48
49
+ func generateCommit (repoPath , email , fullName string ) error {
50
+ //Generate random file
51
+ data := make ([]byte , 1024 )
52
+ _ , err := rand .Read (data )
53
+ if err != nil {
54
+ return err
55
+ }
56
+ tmpFile , err := ioutil .TempFile (repoPath , "data-file-" )
57
+ if err != nil {
58
+ return err
59
+ }
60
+ defer tmpFile .Close ()
61
+ _ , err = tmpFile .Write (data )
62
+ if err != nil {
63
+ return err
64
+ }
65
+
66
+ //Commit
67
+ err = git .AddChanges (repoPath , false , filepath .Base (tmpFile .Name ()))
68
+ if err != nil {
69
+ return err
70
+ }
71
+ err = git .CommitChanges (repoPath , git.CommitChangesOptions {
72
+ Committer : & git.Signature {
73
+ Email : email ,
74
+ Name : fullName ,
75
+ When : time .Now (),
76
+ },
77
+ Author : & git.Signature {
78
+ Email : email ,
79
+ Name : fullName ,
80
+ When : time .Now (),
81
+ },
82
+ Message : fmt .Sprintf ("Testing commit @ %v" , time .Now ()),
83
+ })
84
+ return err
85
+ }
86
+
48
87
func TestGit (t * testing.T ) {
49
88
prepareTestEnv (t )
50
89
@@ -55,7 +94,6 @@ func TestGit(t *testing.T) {
55
94
u .Path = "user2/repo1.git"
56
95
57
96
t .Run ("Standard" , func (t * testing.T ) {
58
-
59
97
t .Run ("CloneNoLogin" , func (t * testing.T ) {
60
98
dstLocalPath , err := ioutil .TempDir ("" , "repo1" )
61
99
assert .NoError (t , err )
@@ -88,32 +126,8 @@ func TestGit(t *testing.T) {
88
126
})
89
127
90
128
t .Run ("PushCommit" , func (t * testing.T ) {
91
- data := make ([]byte , 1024 )
92
- _ , err := rand .Read (data )
129
+ err = generateCommit (
dstPath ,
"[email protected] " ,
"User Two" )
93
130
assert .NoError (t , err )
94
- tmpFile , err := ioutil .TempFile (dstPath , "data-file-" )
95
- defer tmpFile .Close ()
96
- _ , err = tmpFile .Write (data )
97
- assert .NoError (t , err )
98
-
99
- //Commit
100
- err = git .AddChanges (dstPath , false , filepath .Base (tmpFile .Name ()))
101
- assert .NoError (t , err )
102
- err = git .CommitChanges (dstPath , git.CommitChangesOptions {
103
- Committer : & git.Signature {
104
-
105
- Name : "User Two" ,
106
- When : time .Now (),
107
- },
108
- Author : & git.Signature {
109
-
110
- Name : "User Two" ,
111
- When : time .Now (),
112
- },
113
- Message : "Testing commit" ,
114
- })
115
- assert .NoError (t , err )
116
-
117
131
//Push
118
132
err = git .Push (dstPath , git.PushOptions {
119
133
Branch : "master" ,
@@ -125,39 +139,15 @@ func TestGit(t *testing.T) {
125
139
})
126
140
t .Run ("LFS" , func (t * testing.T ) {
127
141
t .Run ("PushCommit" , func (t * testing.T ) {
128
- /* Generate random file */
129
- data := make ([]byte , 1024 )
130
- _ , err := rand .Read (data )
131
- assert .NoError (t , err )
132
- tmpFile , err := ioutil .TempFile (dstPath , "data-file-" )
133
- defer tmpFile .Close ()
134
- _ , err = tmpFile .Write (data )
135
- assert .NoError (t , err )
136
-
137
142
//Setup git LFS
138
143
_ , err = git .NewCommand ("lfs" ).AddArguments ("install" ).RunInDir (dstPath )
139
144
assert .NoError (t , err )
140
145
_ , err = git .NewCommand ("lfs" ).AddArguments ("track" , "data-file-*" ).RunInDir (dstPath )
141
146
assert .NoError (t , err )
142
-
143
- //Commit
144
- err = git .AddChanges (dstPath , false , ".gitattributes" , filepath .Base (tmpFile .Name ()))
145
- assert .NoError (t , err )
146
- err = git .CommitChanges (dstPath , git.CommitChangesOptions {
147
- Committer : & git.Signature {
148
-
149
- Name : "User Two" ,
150
- When : time .Now (),
151
- },
152
- Author : & git.Signature {
153
-
154
- Name : "User Two" ,
155
- When : time .Now (),
156
- },
157
- Message : "Testing LFS " ,
158
- })
147
+ err = git .AddChanges (dstPath , false , ".gitattributes" )
159
148
assert .NoError (t , err )
160
149
150
+ err = generateCommit (
dstPath ,
"[email protected] " ,
"User Two" )
161
151
//Push
162
152
u .User = url .UserPassword ("user2" , userPassword )
163
153
err = git .Push (dstPath , git.PushOptions {
0 commit comments