2017-06-02 21:46:56 -06:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
2017-06-29 09:11:38 -06:00
|
|
|
"fmt"
|
2017-06-02 21:46:56 -06:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
2020-04-07 15:52:01 -06:00
|
|
|
"time"
|
2017-06-02 21:46:56 -06:00
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-16 01:53:21 -07:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2020-06-08 20:46:51 -06:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-12-15 14:11:02 -07:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
2022-04-03 03:46:48 -06:00
|
|
|
"code.gitea.io/gitea/modules/translation/i18n"
|
2017-12-15 14:11:02 -07:00
|
|
|
|
2021-05-05 21:12:50 -06:00
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-06-02 21:46:56 -06:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-06-29 09:11:38 -06:00
|
|
|
func createNewRelease(t *testing.T, session *TestSession, repoURL, tag, title string, preRelease, draft bool) {
|
|
|
|
req := NewRequest(t, "GET", repoURL+"/releases/new")
|
2017-07-07 13:36:47 -06:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 09:11:38 -06:00
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
2020-02-25 13:28:47 -07:00
|
|
|
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
|
2017-06-29 09:11:38 -06:00
|
|
|
assert.True(t, exists, "The template has changed")
|
|
|
|
|
|
|
|
postData := map[string]string{
|
|
|
|
"_csrf": htmlDoc.GetCSRF(),
|
|
|
|
"tag_name": tag,
|
|
|
|
"tag_target": "master",
|
|
|
|
"title": title,
|
|
|
|
"content": "",
|
|
|
|
}
|
|
|
|
if preRelease {
|
|
|
|
postData["prerelease"] = "on"
|
|
|
|
}
|
|
|
|
if draft {
|
|
|
|
postData["draft"] = "Save Draft"
|
|
|
|
}
|
|
|
|
req = NewRequestWithValues(t, "POST", link, postData)
|
|
|
|
|
2022-03-22 22:54:07 -06:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusSeeOther)
|
2017-06-29 09:11:38 -06:00
|
|
|
|
2017-12-15 14:11:02 -07:00
|
|
|
test.RedirectURL(resp) // check that redirect URL exists
|
2017-06-29 09:11:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
|
|
|
|
req := NewRequest(t, "GET", repoURL+"/releases")
|
2017-07-07 13:36:47 -06:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 09:11:38 -06:00
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
|
|
|
|
assert.EqualValues(t, label, labelText)
|
2020-11-02 16:10:22 -07:00
|
|
|
titleText := htmlDoc.doc.Find("#release-list > li .detail h4 a").First().Text()
|
2017-06-29 09:11:38 -06:00
|
|
|
assert.EqualValues(t, version, titleText)
|
|
|
|
|
|
|
|
releaseList := htmlDoc.doc.Find("#release-list > li")
|
|
|
|
assert.EqualValues(t, count, releaseList.Length())
|
|
|
|
}
|
|
|
|
|
2017-06-02 21:46:56 -06:00
|
|
|
func TestViewReleases(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-02 21:46:56 -06:00
|
|
|
|
2017-06-16 22:49:45 -06:00
|
|
|
session := loginUser(t, "user2")
|
2017-06-09 18:41:36 -06:00
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 13:36:47 -06:00
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
2020-04-07 15:52:01 -06:00
|
|
|
|
|
|
|
// if CI is to slow this test fail, so lets wait a bit
|
|
|
|
time.Sleep(time.Millisecond * 100)
|
2017-06-02 21:46:56 -06:00
|
|
|
}
|
2017-06-17 21:38:24 -06:00
|
|
|
|
|
|
|
func TestViewReleasesNoLogin(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-17 21:38:24 -06:00
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 13:36:47 -06:00
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-06-17 21:38:24 -06:00
|
|
|
}
|
2017-06-29 09:11:38 -06:00
|
|
|
|
|
|
|
func TestCreateRelease(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 09:11:38 -06:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 4)
|
2017-06-29 09:11:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleasePreRelease(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 09:11:38 -06:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 4)
|
2017-06-29 09:11:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleaseDraft(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 09:11:38 -06:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 4)
|
2017-06-29 09:11:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleasePaging(t *testing.T) {
|
2019-11-25 16:21:37 -07:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 09:11:38 -06:00
|
|
|
|
2020-06-08 20:46:51 -06:00
|
|
|
oldAPIDefaultNum := setting.API.DefaultPagingNum
|
|
|
|
defer func() {
|
|
|
|
setting.API.DefaultPagingNum = oldAPIDefaultNum
|
|
|
|
}()
|
|
|
|
setting.API.DefaultPagingNum = 10
|
|
|
|
|
2017-06-29 09:11:38 -06:00
|
|
|
session := loginUser(t, "user2")
|
2021-07-08 05:38:13 -06:00
|
|
|
// Create enough releases to have paging
|
2017-06-29 09:11:38 -06:00
|
|
|
for i := 0; i < 12; i++ {
|
|
|
|
version := fmt.Sprintf("v0.0.%d", i)
|
|
|
|
createNewRelease(t, session, "/user2/repo1", version, version, false, false)
|
|
|
|
}
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.12", "v0.0.12", false, true)
|
|
|
|
|
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.12", i18n.Tr("en", "repo.release.draft"), 10)
|
|
|
|
|
2019-02-19 00:19:28 -07:00
|
|
|
// Check that user4 does not see draft and still see 10 latest releases
|
|
|
|
session2 := loginUser(t, "user4")
|
2017-06-29 09:11:38 -06:00
|
|
|
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", i18n.Tr("en", "repo.release.stable"), 10)
|
|
|
|
}
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
func TestViewReleaseListNoLogin(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
link := repo.Link() + "/releases"
|
|
|
|
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
releases := htmlDoc.Find("#release-list li.ui.grid")
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.Equal(t, 2, releases.Length())
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
links := make([]string, 0, 5)
|
|
|
|
releases.Each(func(i int, s *goquery.Selection) {
|
|
|
|
link, exist := s.Find(".release-list-title a").Attr("href")
|
|
|
|
if !exist {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
links = append(links, link)
|
|
|
|
})
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.EqualValues(t, []string{"/user2/repo1/releases/tag/v1.0", "/user2/repo1/releases/tag/v1.1"}, links)
|
2021-05-05 21:12:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestViewReleaseListLogin(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
link := repo.Link() + "/releases"
|
|
|
|
|
|
|
|
session := loginUser(t, "user1")
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
releases := htmlDoc.Find("#release-list li.ui.grid")
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.Equal(t, 3, releases.Length())
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
links := make([]string, 0, 5)
|
|
|
|
releases.Each(func(i int, s *goquery.Selection) {
|
|
|
|
link, exist := s.Find(".release-list-title a").Attr("href")
|
|
|
|
if !exist {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
links = append(links, link)
|
|
|
|
})
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.EqualValues(t, []string{
|
|
|
|
"/user2/repo1/releases/tag/draft-release",
|
|
|
|
"/user2/repo1/releases/tag/v1.0",
|
|
|
|
"/user2/repo1/releases/tag/v1.1",
|
|
|
|
}, links)
|
2021-05-05 21:12:50 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestViewTagsList(t *testing.T) {
|
|
|
|
defer prepareTestEnv(t)()
|
|
|
|
|
2021-12-09 18:27:50 -07:00
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1}).(*repo_model.Repository)
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
link := repo.Link() + "/tags"
|
|
|
|
|
|
|
|
session := loginUser(t, "user1")
|
|
|
|
req := NewRequest(t, "GET", link)
|
|
|
|
rsp := session.MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, rsp.Body)
|
|
|
|
tags := htmlDoc.Find(".tag-list tr")
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.Equal(t, 3, tags.Length())
|
2021-05-05 21:12:50 -06:00
|
|
|
|
|
|
|
tagNames := make([]string, 0, 5)
|
|
|
|
tags.Each(func(i int, s *goquery.Selection) {
|
|
|
|
tagNames = append(tagNames, s.Find(".tag a.df.ac").Text())
|
|
|
|
})
|
|
|
|
|
2021-06-17 02:58:10 -06:00
|
|
|
assert.EqualValues(t, []string{"v1.0", "delete-tag", "v1.1"}, tagNames)
|
2021-05-05 21:12:50 -06:00
|
|
|
}
|