@@ -19,7 +19,6 @@ import (
1919 "code.gitea.io/gitea/modules/git"
2020 "code.gitea.io/gitea/modules/gitrepo"
2121 "code.gitea.io/gitea/modules/setting"
22- "code.gitea.io/gitea/modules/test"
2322 gitea_context "code.gitea.io/gitea/services/context"
2423 "code.gitea.io/gitea/services/migrations"
2524 mirror_service "code.gitea.io/gitea/services/mirror"
@@ -124,78 +123,59 @@ func doRemovePushMirror(ctx APITestContext, address, username, password string,
124123
125124func TestRepoSettingPushMirror (t * testing.T ) {
126125 defer tests .PrepareTestEnv (t )()
126+ setting .Migrations .AllowLocalNetworks = true
127+ assert .NoError (t , migrations .Init ())
127128
128129 session := loginUser (t , "user2" )
129-
130- repoPrefix := "/user2/repo2"
131130 repo2 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 2 })
132131
133- defer func () {
134- migrations .Init ()
135- }()
136- defer test .MockVariableValue (& setting .Migrations .AllowedDomains , "127.0.0.1" )()
137- assert .NoError (t , migrations .Init ())
138-
139- // visit repository setting page
140- req := NewRequest (t , "GET" , repoPrefix + "/settings" )
141- resp := session .MakeRequest (t , req , http .StatusOK )
142- htmlDoc := NewHTMLParser (t , resp .Body )
143-
144- onGiteaRun (t , func (t * testing.T , u * url.URL ) {
145- t .Run ("Push Mirror Add" , func (t * testing.T ) {
146- req = NewRequestWithValues (t , "POST" , repoPrefix + "/settings" , map [string ]string {
147- "_csrf" : htmlDoc .GetCSRF (),
148- "action" : "push-mirror-add" ,
149- "push_mirror_address" : u .String () + "/user1/repo1.git" ,
150- "push_mirror_interval" : "0" ,
151- })
152- session .MakeRequest (t , req , http .StatusSeeOther )
153-
154- flashCookie := session .GetCookie (gitea_context .CookieNameFlash )
155- assert .NotNil (t , flashCookie )
156- assert .Contains (t , flashCookie .Value , "success" )
157-
158- mirrors , cnt , err := repo_model .GetPushMirrorsByRepoID (db .DefaultContext , repo2 .ID , db.ListOptions {})
159- assert .NoError (t , err )
160- assert .Len (t , mirrors , 1 )
161- assert .EqualValues (t , 1 , cnt )
162- assert .EqualValues (t , 0 , mirrors [0 ].Interval )
132+ t .Run ("Push Mirror Add" , func (t * testing.T ) {
133+ req := NewRequestWithValues (t , "POST" , "/user2/repo2/settings" , map [string ]string {
134+ "_csrf" : GetUserCSRFToken (t , session ),
135+ "action" : "push-mirror-add" ,
136+ "push_mirror_address" : "https://127.0.0.1/user1/repo1.git" ,
137+ "push_mirror_interval" : "24h" ,
163138 })
139+ session .MakeRequest (t , req , http .StatusSeeOther )
164140
165- mirrors , _ , _ := repo_model .GetPushMirrorsByRepoID (db .DefaultContext , repo2 .ID , db.ListOptions {})
166-
167- t .Run ("Push Mirror Update" , func (t * testing.T ) {
168- req := NewRequestWithValues (t , "POST" , repoPrefix + "/settings" , map [string ]string {
169- "_csrf" : htmlDoc .GetCSRF (),
170- "action" : "push-mirror-update" ,
171- "push_mirror_id" : strconv .FormatInt (mirrors [0 ].ID , 10 ),
172- "push_mirror_interval" : "10m0s" ,
173- })
174- session .MakeRequest (t , req , http .StatusSeeOther )
175-
176- mirror , err := repo_model .GetPushMirrorByID (db .DefaultContext , mirrors [0 ].ID )
177- assert .NoError (t , err )
178- assert .EqualValues (t , 10 * time .Minute , mirror .Interval )
179-
180- req = NewRequestWithValues (t , "POST" , repoPrefix + "/settings" , map [string ]string {
181- "_csrf" : htmlDoc .GetCSRF (),
182- "action" : "push-mirror-update" ,
183- "push_mirror_id" : strconv .FormatInt (9999 , 10 ), // 1 is an mirror ID which is not exist
184- "push_mirror_interval" : "10m0s" ,
185- })
186- session .MakeRequest (t , req , http .StatusNotFound )
187- })
141+ flashCookie := session .GetCookie (gitea_context .CookieNameFlash )
142+ assert .NotNil (t , flashCookie )
143+ assert .Contains (t , flashCookie .Value , "success" )
188144
189- t .Run ("Push Mirror Remove" , func (t * testing.T ) {
190- req := NewRequestWithValues (t , "POST" , repoPrefix + "/settings" , map [string ]string {
191- "_csrf" : htmlDoc .GetCSRF (),
192- "action" : "push-mirror-remove" ,
193- "push_mirror_id" : strconv .FormatInt (mirrors [0 ].ID , 10 ),
194- })
195- session .MakeRequest (t , req , http .StatusSeeOther )
145+ pushMirrors , cnt , err := repo_model .GetPushMirrorsByRepoID (db .DefaultContext , repo2 .ID , db.ListOptions {})
146+ assert .NoError (t , err )
147+ assert .Len (t , pushMirrors , 1 )
148+ assert .EqualValues (t , 1 , cnt )
149+ assert .EqualValues (t , 24 * time .Hour , pushMirrors [0 ].Interval )
150+ repo2PushMirrorID := pushMirrors [0 ].ID
151+
152+ // update repo2 push mirror
153+ req = NewRequestWithValues (t , "POST" , "/user2/repo2/settings" , map [string ]string {
154+ "_csrf" : GetUserCSRFToken (t , session ),
155+ "action" : "push-mirror-update" ,
156+ "push_mirror_id" : strconv .FormatInt (repo2PushMirrorID , 10 ),
157+ "push_mirror_interval" : "10m0s" ,
158+ })
159+ session .MakeRequest (t , req , http .StatusSeeOther )
160+ mirror := unittest .AssertExistsAndLoadBean (t , & repo_model.PushMirror {ID : repo2PushMirrorID })
161+ assert .EqualValues (t , 10 * time .Minute , mirror .Interval )
162+
163+ // avoid updating repo1 push mirror
164+ req = NewRequestWithValues (t , "POST" , "/user2/repo1/settings" , map [string ]string {
165+ "_csrf" : GetUserCSRFToken (t , session ),
166+ "action" : "push-mirror-update" ,
167+ "push_mirror_id" : strconv .FormatInt (repo2PushMirrorID , 10 ),
168+ "push_mirror_interval" : "20m0s" ,
169+ })
170+ session .MakeRequest (t , req , http .StatusNotFound )
196171
197- _ , err := repo_model .GetPushMirrorByID (db .DefaultContext , mirrors [0 ].ID )
198- assert .Error (t , err )
172+ // delete repo2 push mirror
173+ req = NewRequestWithValues (t , "POST" , "/user2/repo2/settings" , map [string ]string {
174+ "_csrf" : GetUserCSRFToken (t , session ),
175+ "action" : "push-mirror-remove" ,
176+ "push_mirror_id" : strconv .FormatInt (repo2PushMirrorID , 10 ),
199177 })
178+ session .MakeRequest (t , req , http .StatusSeeOther )
179+ unittest .AssertNotExistsBean (t , & repo_model.PushMirror {ID : repo2PushMirrorID })
200180 })
201181}
0 commit comments