You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_test.go 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2019 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/context"
  10. api "code.gitea.io/gitea/modules/structs"
  11. "code.gitea.io/gitea/modules/test"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestRepoEdit(t *testing.T) {
  15. models.PrepareTestEnv(t)
  16. ctx := test.MockContext(t, "user2/repo1")
  17. test.LoadRepo(t, ctx, 1)
  18. test.LoadUser(t, ctx, 2)
  19. ctx.Repo.Owner = ctx.User
  20. description := "new description"
  21. website := "http://wwww.newwebsite.com"
  22. private := true
  23. hasIssues := false
  24. hasWiki := false
  25. defaultBranch := "master"
  26. hasPullRequests := true
  27. ignoreWhitespaceConflicts := true
  28. allowMerge := false
  29. allowRebase := false
  30. allowRebaseMerge := false
  31. allowSquashMerge := false
  32. archived := true
  33. opts := api.EditRepoOption{
  34. Name: &ctx.Repo.Repository.Name,
  35. Description: &description,
  36. Website: &website,
  37. Private: &private,
  38. HasIssues: &hasIssues,
  39. HasWiki: &hasWiki,
  40. DefaultBranch: &defaultBranch,
  41. HasPullRequests: &hasPullRequests,
  42. IgnoreWhitespaceConflicts: &ignoreWhitespaceConflicts,
  43. AllowMerge: &allowMerge,
  44. AllowRebase: &allowRebase,
  45. AllowRebaseMerge: &allowRebaseMerge,
  46. AllowSquash: &allowSquashMerge,
  47. Archived: &archived,
  48. }
  49. Edit(&context.APIContext{Context: ctx, Org: nil}, opts)
  50. assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
  51. models.AssertExistsAndLoadBean(t, &models.Repository{
  52. ID: 1,
  53. }, models.Cond("name = ? AND is_archived = 1", *opts.Name))
  54. }
  55. func TestRepoEditNameChange(t *testing.T) {
  56. models.PrepareTestEnv(t)
  57. ctx := test.MockContext(t, "user2/repo1")
  58. test.LoadRepo(t, ctx, 1)
  59. test.LoadUser(t, ctx, 2)
  60. ctx.Repo.Owner = ctx.User
  61. name := "newname"
  62. opts := api.EditRepoOption{
  63. Name: &name,
  64. }
  65. Edit(&context.APIContext{Context: ctx, Org: nil}, opts)
  66. assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
  67. models.AssertExistsAndLoadBean(t, &models.Repository{
  68. ID: 1,
  69. }, models.Cond("name = ?", opts.Name))
  70. }