99 "fmt"
1010 "net/http"
1111 "net/url"
12+ "strconv"
1213 "testing"
1314
1415 "code.gitea.io/gitea/models"
@@ -68,6 +69,12 @@ func testMirrorPush(t *testing.T, u *url.URL) {
6869 assert .NoError (t , err )
6970
7071 assert .Equal (t , srcCommit .ID , mirrorCommit .ID )
72+
73+ // Cleanup
74+ doRemovePushMirror (ctx , fmt .Sprintf ("%s%s/%s" , u .String (), url .PathEscape (ctx .Username ), url .PathEscape (mirrorRepo .Name )), user .LowerName , userPassword , int (mirrors [0 ].ID ))(t )
75+ mirrors , err = repo_model .GetPushMirrorsByRepoID (srcRepo .ID )
76+ assert .NoError (t , err )
77+ assert .Len (t , mirrors , 0 )
7178}
7279
7380func doCreatePushMirror (ctx APITestContext , address , username , password string ) func (t * testing.T ) {
@@ -89,3 +96,24 @@ func doCreatePushMirror(ctx APITestContext, address, username, password string)
8996 assert .Contains (t , flashCookie .Value , "success" )
9097 }
9198}
99+
100+ func doRemovePushMirror (ctx APITestContext , address , username , password string , pushMirrorID int ) func (t * testing.T ) {
101+ return func (t * testing.T ) {
102+ csrf := GetCSRF (t , ctx .Session , fmt .Sprintf ("/%s/%s/settings" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame )))
103+
104+ req := NewRequestWithValues (t , "POST" , fmt .Sprintf ("/%s/%s/settings" , url .PathEscape (ctx .Username ), url .PathEscape (ctx .Reponame )), map [string ]string {
105+ "_csrf" : csrf ,
106+ "action" : "push-mirror-remove" ,
107+ "push_mirror_id" : strconv .Itoa (pushMirrorID ),
108+ "push_mirror_address" : address ,
109+ "push_mirror_username" : username ,
110+ "push_mirror_password" : password ,
111+ "push_mirror_interval" : "0" ,
112+ })
113+ ctx .Session .MakeRequest (t , req , http .StatusFound )
114+
115+ flashCookie := ctx .Session .GetCookie ("macaron_flash" )
116+ assert .NotNil (t , flashCookie )
117+ assert .Contains (t , flashCookie .Value , "success" )
118+ }
119+ }
0 commit comments