@@ -11,7 +11,9 @@ import (
1111 "strings"
1212 "testing"
1313
14+ auth_model "code.gitea.io/gitea/models/auth"
1415 "code.gitea.io/gitea/modules/git"
16+ api "code.gitea.io/gitea/modules/structs"
1517 "code.gitea.io/gitea/modules/util"
1618 "code.gitea.io/gitea/tests"
1719
@@ -71,3 +73,46 @@ func Test_RepoWikiPages(t *testing.T) {
7173 assert .Equal (t , expectedPagePaths [i ], pagePath )
7274 })
7375}
76+
77+ func Test_WikiClone (t * testing.T ) {
78+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
79+ username := "user2"
80+ reponame := "repo1"
81+ wikiPath := username + "/" + reponame + ".wiki.git"
82+ keyname := "my-testing-key"
83+ baseAPITestContext := NewAPITestContext (t , username , "repo1" , auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
84+
85+ u .Path = wikiPath
86+
87+ t .Run ("Clone HTTP" , func (t * testing.T ) {
88+ defer tests .PrintCurrentTest (t )()
89+
90+ dstLocalPath := t .TempDir ()
91+ assert .NoError (t , git .Clone (t .Context (), u .String (), dstLocalPath , git.CloneRepoOptions {}))
92+ content , err := os .ReadFile (filepath .Join (dstLocalPath , "Home.md" ))
93+ assert .NoError (t , err )
94+ assert .Equal (t , "# Home page\n \n This is the home page!\n " , string (content ))
95+ })
96+
97+ t .Run ("Clone SSH" , func (t * testing.T ) {
98+ defer tests .PrintCurrentTest (t )()
99+
100+ dstLocalPath := t .TempDir ()
101+ sshURL := createSSHUrl (wikiPath , u )
102+
103+ withKeyFile (t , keyname , func (keyFile string ) {
104+ var keyID int64
105+ t .Run ("CreateUserKey" , doAPICreateUserKey (baseAPITestContext , "test-key" , keyFile , func (t * testing.T , key api.PublicKey ) {
106+ keyID = key .ID
107+ }))
108+ assert .NotZero (t , keyID )
109+
110+ // Setup clone folder
111+ assert .NoError (t , git .Clone (t .Context (), sshURL .String (), dstLocalPath , git.CloneRepoOptions {}))
112+ content , err := os .ReadFile (filepath .Join (dstLocalPath , "Home.md" ))
113+ assert .NoError (t , err )
114+ assert .Equal (t , "# Home page\n \n This is the home page!\n " , string (content ))
115+ })
116+ })
117+ })
118+ }
0 commit comments