Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

release_test.go 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright 2017 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 integrations
  5. import (
  6. "fmt"
  7. "net/http"
  8. "testing"
  9. "github.com/Unknwon/i18n"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
  13. req := NewRequest(t, "GET", repoURL+"/releases/new")
  14. resp := session.MakeRequest(t, req, http.StatusOK)
  15. htmlDoc := NewHTMLParser(t, resp.Body)
  16. link, exists := htmlDoc.doc.Find("form").Attr("action")
  17. assert.True(t, exists, "The template has changed")
  18. postData := map[string]string{
  19. "_csrf": htmlDoc.GetCSRF(),
  20. "tag_name": tag,
  21. "tag_target": "master",
  22. "title": title,
  23. "content": "",
  24. }
  25. if preRelease {
  26. postData["prerelease"] = "on"
  27. }
  28. if draft {
  29. postData["draft"] = "Save Draft"
  30. }
  31. req = NewRequestWithValues(t, "POST", link, postData)
  32. resp = session.MakeRequest(t, req, http.StatusFound)
  33. RedirectURL(t, resp) // check that redirect URL exists
  34. }
  35. func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
  36. req := NewRequest(t, "GET", repoURL+"/releases")
  37. resp := session.MakeRequest(t, req, http.StatusOK)
  38. htmlDoc := NewHTMLParser(t, resp.Body)
  39. labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
  40. assert.EqualValues(t, label, labelText)
  41. titleText := htmlDoc.doc.Find("#release-list > li .detail h3 a").First().Text()
  42. assert.EqualValues(t, version, titleText)
  43. releaseList := htmlDoc.doc.Find("#release-list > li")
  44. assert.EqualValues(t, count, releaseList.Length())
  45. }
  46. func TestViewReleases(t *testing.T) {
  47. prepareTestEnv(t)
  48. session := loginUser(t, "user2")
  49. req := NewRequest(t, "GET", "/user2/repo1/releases")
  50. session.MakeRequest(t, req, http.StatusOK)
  51. }
  52. func TestViewReleasesNoLogin(t *testing.T) {
  53. prepareTestEnv(t)
  54. req := NewRequest(t, "GET", "/user2/repo1/releases")
  55. MakeRequest(t, req, http.StatusOK)
  56. }
  57. func TestCreateRelease(t *testing.T) {
  58. prepareTestEnv(t)
  59. session := loginUser(t, "user2")
  60. createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
  61. checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 1)
  62. }
  63. func TestCreateReleasePreRelease(t *testing.T) {
  64. prepareTestEnv(t)
  65. session := loginUser(t, "user2")
  66. createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
  67. checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 1)
  68. }
  69. func TestCreateReleaseDraft(t *testing.T) {
  70. prepareTestEnv(t)
  71. session := loginUser(t, "user2")
  72. createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
  73. checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 1)
  74. }
  75. func TestCreateReleasePaging(t *testing.T) {
  76. prepareTestEnv(t)
  77. session := loginUser(t, "user2")
  78. // Create enaugh releases to have paging
  79. for i := 0; i < 12; i++ {
  80. version := fmt.Sprintf("v0.0.%d", i)
  81. createNewRelease(t, session, "/user2/repo1", version, version, false, false)
  82. }
  83. createNewRelease(t, session, "/user2/repo1", "v0.0.12", "v0.0.12", false, true)
  84. checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", i18n.Tr("en", "repo.release.draft"), 10)
  85. // Check that user3 does not see draft and still see 10 latest releases
  86. session2 := loginUser(t, "user3")
  87. checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", i18n.Tr("en", "repo.release.stable"), 10)
  88. }