|
9 | 9 | "net/url"
|
10 | 10 | "testing"
|
11 | 11 |
|
| 12 | + "code.gitea.io/gitea/models/db" |
12 | 13 | repo_model "code.gitea.io/gitea/models/repo"
|
13 | 14 | "code.gitea.io/gitea/models/unittest"
|
14 | 15 | "code.gitea.io/gitea/modules/git"
|
@@ -221,3 +222,32 @@ func TestWikiRaw(t *testing.T) {
|
221 | 222 | }
|
222 | 223 | }
|
223 | 224 | }
|
| 225 | + |
| 226 | +func TestDefaultWikiBranch(t *testing.T) { |
| 227 | + unittest.PrepareTestEnv(t) |
| 228 | + |
| 229 | + assert.NoError(t, repo_model.UpdateRepositoryCols(db.DefaultContext, &repo_model.Repository{ID: 1, DefaultWikiBranch: "wrong-branch"})) |
| 230 | + |
| 231 | + ctx, _ := contexttest.MockContext(t, "user2/repo1/wiki") |
| 232 | + ctx.SetParams("*", "Home") |
| 233 | + contexttest.LoadRepo(t, ctx, 1) |
| 234 | + assert.Equal(t, "wrong-branch", ctx.Repo.Repository.DefaultWikiBranch) |
| 235 | + Wiki(ctx) // after the visiting, the out-of-sync database record will update the branch name to "master" |
| 236 | + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 237 | + assert.Equal(t, "master", ctx.Repo.Repository.DefaultWikiBranch) |
| 238 | + |
| 239 | + // invalid branch name should fail |
| 240 | + assert.Error(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "the bad name")) |
| 241 | + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 242 | + assert.Equal(t, "master", repo.DefaultWikiBranch) |
| 243 | + |
| 244 | + // the same branch name, should succeed (actually a no-op) |
| 245 | + assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "master")) |
| 246 | + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 247 | + assert.Equal(t, "master", repo.DefaultWikiBranch) |
| 248 | + |
| 249 | + // change to another name |
| 250 | + assert.NoError(t, wiki_service.ChangeDefaultWikiBranch(db.DefaultContext, repo, "main")) |
| 251 | + repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}) |
| 252 | + assert.Equal(t, "main", repo.DefaultWikiBranch) |
| 253 | +} |
0 commit comments