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.

release_test.go 2.5KB

Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
3 years ago
Move macaron to chi (#14293) Use [chi](https://github.com/go-chi/chi) instead of the forked [macaron](https://gitea.com/macaron/macaron). Since macaron and chi have conflicts with session share, this big PR becomes a have-to thing. According my previous idea, we can replace macaron step by step but I'm wrong. :( Below is a list of big changes on this PR. - [x] Define `context.ResponseWriter` interface with an implementation `context.Response`. - [x] Use chi instead of macaron, and also a customize `Route` to wrap chi so that the router usage is similar as before. - [x] Create different routers for `web`, `api`, `internal` and `install` so that the codes will be more clear and no magic . - [x] Use https://github.com/unrolled/render instead of macaron's internal render - [x] Use https://github.com/NYTimes/gziphandler instead of https://gitea.com/macaron/gzip - [x] Use https://gitea.com/go-chi/session which is a modified version of https://gitea.com/macaron/session and removed `nodb` support since it will not be maintained. **BREAK** - [x] Use https://gitea.com/go-chi/captcha which is a modified version of https://gitea.com/macaron/captcha - [x] Use https://gitea.com/go-chi/cache which is a modified version of https://gitea.com/macaron/cache - [x] Use https://gitea.com/go-chi/binding which is a modified version of https://gitea.com/macaron/binding - [x] Use https://github.com/go-chi/cors instead of https://gitea.com/macaron/cors - [x] Dropped https://gitea.com/macaron/i18n and make a new one in `code.gitea.io/gitea/modules/translation` - [x] Move validation form structs from `code.gitea.io/gitea/modules/auth` to `code.gitea.io/gitea/modules/forms` to avoid dependency cycle. - [x] Removed macaron log service because it's not need any more. **BREAK** - [x] All form structs have to be get by `web.GetForm(ctx)` in the route function but not as a function parameter on routes definition. - [x] Move Git HTTP protocol implementation to use routers directly. - [x] Fix the problem that chi routes don't support trailing slash but macaron did. - [x] `/api/v1/swagger` now will be redirect to `/api/swagger` but not render directly so that `APIContext` will not create a html render. Notices: - Chi router don't support request with trailing slash - Integration test `TestUserHeatmap` maybe mysql version related. It's failed on my macOS(mysql 5.7.29 installed via brew) but succeed on CI. Co-authored-by: 6543 <6543@obermui.de>
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package repo
  4. import (
  5. "testing"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/models/unittest"
  8. "code.gitea.io/gitea/modules/test"
  9. "code.gitea.io/gitea/modules/web"
  10. "code.gitea.io/gitea/services/forms"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestNewReleasePost(t *testing.T) {
  14. for _, testCase := range []struct {
  15. RepoID int64
  16. UserID int64
  17. TagName string
  18. Form forms.NewReleaseForm
  19. }{
  20. {
  21. RepoID: 1,
  22. UserID: 2,
  23. TagName: "v1.1", // pre-existing tag
  24. Form: forms.NewReleaseForm{
  25. TagName: "newtag",
  26. Target: "master",
  27. Title: "title",
  28. Content: "content",
  29. },
  30. },
  31. {
  32. RepoID: 1,
  33. UserID: 2,
  34. TagName: "newtag",
  35. Form: forms.NewReleaseForm{
  36. TagName: "newtag",
  37. Target: "master",
  38. Title: "title",
  39. Content: "content",
  40. },
  41. },
  42. } {
  43. unittest.PrepareTestEnv(t)
  44. ctx := test.MockContext(t, "user2/repo1/releases/new")
  45. test.LoadUser(t, ctx, 2)
  46. test.LoadRepo(t, ctx, 1)
  47. test.LoadGitRepo(t, ctx)
  48. web.SetForm(ctx, &testCase.Form)
  49. NewReleasePost(ctx)
  50. unittest.AssertExistsAndLoadBean(t, &repo_model.Release{
  51. RepoID: 1,
  52. PublisherID: 2,
  53. TagName: testCase.Form.TagName,
  54. Target: testCase.Form.Target,
  55. Title: testCase.Form.Title,
  56. Note: testCase.Form.Content,
  57. }, unittest.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
  58. ctx.Repo.GitRepo.Close()
  59. }
  60. }
  61. func TestNewReleasesList(t *testing.T) {
  62. unittest.PrepareTestEnv(t)
  63. ctx := test.MockContext(t, "user2/repo-release/releases")
  64. test.LoadUser(t, ctx, 2)
  65. test.LoadRepo(t, ctx, 57)
  66. test.LoadGitRepo(t, ctx)
  67. t.Cleanup(func() { ctx.Repo.GitRepo.Close() })
  68. Releases(ctx)
  69. releases := ctx.Data["Releases"].([]*repo_model.Release)
  70. type computedFields struct {
  71. NumCommitsBehind int64
  72. TargetBehind string
  73. }
  74. expectedComputation := map[string]computedFields{
  75. "v1.0": {
  76. NumCommitsBehind: 3,
  77. TargetBehind: "main",
  78. },
  79. "v1.1": {
  80. NumCommitsBehind: 1,
  81. TargetBehind: "main",
  82. },
  83. "v2.0": {
  84. NumCommitsBehind: 0,
  85. TargetBehind: "main",
  86. },
  87. "non-existing-target-branch": {
  88. NumCommitsBehind: 1,
  89. TargetBehind: "main",
  90. },
  91. "empty-target-branch": {
  92. NumCommitsBehind: 1,
  93. TargetBehind: "main",
  94. },
  95. }
  96. for _, r := range releases {
  97. actual := computedFields{
  98. NumCommitsBehind: r.NumCommitsBehind,
  99. TargetBehind: r.TargetBehind,
  100. }
  101. assert.Equal(t, expectedComputation[r.TagName], actual, "wrong computed fields for %s: %#v", r.TagName, r)
  102. }
  103. }