@@ -323,3 +323,82 @@ func TestSSHPushMirror(t *testing.T) {
323323 })
324324 })
325325}
326+
327+ func TestPushMirrorSettings (t * testing.T ) {
328+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
329+ defer test .MockVariableValue (& setting .Migrations .AllowLocalNetworks , true )()
330+ defer test .MockVariableValue (& setting .Mirror .Enabled , true )()
331+ require .NoError (t , migrations .Init ())
332+
333+ user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
334+ srcRepo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 2 })
335+ srcRepo2 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 3 })
336+ assert .False (t , srcRepo .HasWiki ())
337+ sess := loginUser (t , user .Name )
338+ pushToRepo , _ , f := tests .CreateDeclarativeRepoWithOptions (t , user , tests.DeclarativeRepoOptions {
339+ Name : optional .Some ("push-mirror-test" ),
340+ AutoInit : optional .Some (false ),
341+ EnabledUnits : optional .Some ([]unit.Type {unit .TypeCode }),
342+ })
343+ defer f ()
344+
345+ t .Run ("Adding" , func (t * testing.T ) {
346+ defer tests .PrintCurrentTest (t )()
347+
348+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/settings" , srcRepo2 .FullName ()), map [string ]string {
349+ "_csrf" : GetCSRF (t , sess , fmt .Sprintf ("/%s/settings" , srcRepo2 .FullName ())),
350+ "action" : "push-mirror-add" ,
351+ "push_mirror_address" : u .String () + pushToRepo .FullName (),
352+ "push_mirror_interval" : "0" ,
353+ })
354+ sess .MakeRequest (t , req , http .StatusSeeOther )
355+
356+ req = NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ()), map [string ]string {
357+ "_csrf" : GetCSRF (t , sess , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ())),
358+ "action" : "push-mirror-add" ,
359+ "push_mirror_address" : u .String () + pushToRepo .FullName (),
360+ "push_mirror_interval" : "0" ,
361+ })
362+ sess .MakeRequest (t , req , http .StatusSeeOther )
363+
364+ flashCookie := sess .GetCookie (gitea_context .CookieNameFlash )
365+ assert .NotNil (t , flashCookie )
366+ assert .Contains (t , flashCookie .Value , "success" )
367+ })
368+
369+ mirrors , _ , err := repo_model .GetPushMirrorsByRepoID (db .DefaultContext , srcRepo .ID , db.ListOptions {})
370+ require .NoError (t , err )
371+ assert .Len (t , mirrors , 1 )
372+ mirrorID := mirrors [0 ].ID
373+
374+ mirrors , _ , err = repo_model .GetPushMirrorsByRepoID (db .DefaultContext , srcRepo2 .ID , db.ListOptions {})
375+ require .NoError (t , err )
376+ assert .Len (t , mirrors , 1 )
377+
378+ t .Run ("Interval" , func (t * testing.T ) {
379+ defer tests .PrintCurrentTest (t )()
380+
381+ unittest .AssertExistsAndLoadBean (t , & repo_model.PushMirror {ID : mirrorID - 1 })
382+
383+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ()), map [string ]string {
384+ "_csrf" : GetCSRF (t , sess , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ())),
385+ "action" : "push-mirror-update" ,
386+ "push_mirror_id" : strconv .FormatInt (mirrorID - 1 , 10 ),
387+ "push_mirror_interval" : "10m0s" ,
388+ })
389+ sess .MakeRequest (t , req , http .StatusNotFound )
390+
391+ req = NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ()), map [string ]string {
392+ "_csrf" : GetCSRF (t , sess , fmt .Sprintf ("/%s/settings" , srcRepo .FullName ())),
393+ "action" : "push-mirror-update" ,
394+ "push_mirror_id" : strconv .FormatInt (mirrorID , 10 ),
395+ "push_mirror_interval" : "10m0s" ,
396+ })
397+ sess .MakeRequest (t , req , http .StatusSeeOther )
398+
399+ flashCookie := sess .GetCookie (gitea_context .CookieNameFlash )
400+ assert .NotNil (t , flashCookie )
401+ assert .Contains (t , flashCookie .Value , "success" )
402+ })
403+ })
404+ }
0 commit comments