5
5
package models
6
6
7
7
import (
8
- "path"
9
8
"path/filepath"
10
9
"testing"
11
10
11
+ "code.gitea.io/gitea/modules/git"
12
12
"code.gitea.io/gitea/modules/setting"
13
13
14
- "github.com/Unknwon/com"
15
14
"github.com/stretchr/testify/assert"
16
15
)
17
16
@@ -145,13 +144,6 @@ func TestRepository_InitUncyclo(t *testing.T) {
145
144
assert .True (t , repo2 .HasUncyclo ())
146
145
}
147
146
148
- func TestRepository_LocalUncycloPath (t * testing.T ) {
149
- PrepareTestEnv (t )
150
- repo := AssertExistsAndLoadBean (t , & Repository {ID : 1 }).(* Repository )
151
- expected := filepath .Join (setting .AppDataPath , setting .Repository .Local .LocalUncycloPath , "1" )
152
- assert .Equal (t , expected , repo .LocalUncycloPath ())
153
- }
154
-
155
147
func TestRepository_AddUncycloPage (t * testing.T ) {
156
148
assert .NoError (t , PrepareTestDatabase ())
157
149
const wikiContent = "This is the wiki content"
@@ -166,8 +158,15 @@ func TestRepository_AddUncycloPage(t *testing.T) {
166
158
t .Run ("test wiki exist: " + wikiName , func (t * testing.T ) {
167
159
t .Parallel ()
168
160
assert .NoError (t , repo .AddUncycloPage (doer , wikiName , wikiContent , commitMsg ))
169
- expectedPath := path .Join (repo .LocalUncycloPath (), UncycloNameToFilename (wikiName ))
170
- assert .True (t , com .IsExist (expectedPath ))
161
+ // Now need to show that the page has been added:
162
+ gitRepo , err := git .OpenRepository (repo .UncycloPath ())
163
+ assert .NoError (t , err )
164
+ masterTree , err := gitRepo .GetTree ("master" )
165
+ assert .NoError (t , err )
166
+ wikiPath := UncycloNameToFilename (wikiName )
167
+ entry , err := masterTree .GetTreeEntryByPath (wikiPath )
168
+ assert .NoError (t , err )
169
+ assert .Equal (t , wikiPath , entry .Name (), "%s not addded correctly" , wikiName )
171
170
})
172
171
}
173
172
@@ -200,11 +199,20 @@ func TestRepository_EditUncycloPage(t *testing.T) {
200
199
} {
201
200
PrepareTestEnv (t )
202
201
assert .NoError (t , repo .EditUncycloPage (doer , "Home" , newUncycloName , newUncycloContent , commitMsg ))
203
- newPath := path .Join (repo .LocalUncycloPath (), UncycloNameToFilename (newUncycloName ))
204
- assert .True (t , com .IsExist (newPath ))
202
+
203
+ // Now need to show that the page has been added:
204
+ gitRepo , err := git .OpenRepository (repo .UncycloPath ())
205
+ assert .NoError (t , err )
206
+ masterTree , err := gitRepo .GetTree ("master" )
207
+ assert .NoError (t , err )
208
+ wikiPath := UncycloNameToFilename (newUncycloName )
209
+ entry , err := masterTree .GetTreeEntryByPath (wikiPath )
210
+ assert .NoError (t , err )
211
+ assert .Equal (t , wikiPath , entry .Name (), "%s not editted correctly" , newUncycloName )
212
+
205
213
if newUncycloName != "Home" {
206
- oldPath := path . Join ( repo . LocalUncycloPath (), "Home.md" )
207
- assert .False (t , com . IsExist ( oldPath ) )
214
+ _ , err := masterTree . GetTreeEntryByPath ( "Home.md" )
215
+ assert .Error (t , err )
208
216
}
209
217
}
210
218
}
@@ -214,6 +222,13 @@ func TestRepository_DeleteUncycloPage(t *testing.T) {
214
222
repo := AssertExistsAndLoadBean (t , & Repository {ID : 1 }).(* Repository )
215
223
doer := AssertExistsAndLoadBean (t , & User {ID : 2 }).(* User )
216
224
assert .NoError (t , repo .DeleteUncycloPage (doer , "Home" ))
217
- wikiPath := path .Join (repo .LocalUncycloPath (), "Home.md" )
218
- assert .False (t , com .IsExist (wikiPath ))
225
+
226
+ // Now need to show that the page has been added:
227
+ gitRepo , err := git .OpenRepository (repo .UncycloPath ())
228
+ assert .NoError (t , err )
229
+ masterTree , err := gitRepo .GetTree ("master" )
230
+ assert .NoError (t , err )
231
+ wikiPath := UncycloNameToFilename ("Home" )
232
+ _ , err = masterTree .GetTreeEntryByPath (wikiPath )
233
+ assert .Error (t , err )
219
234
}
0 commit comments