2017-06-02 22:46:56 -05: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 10:11:38 -05:00
|
|
|
"fmt"
|
2017-06-02 22:46:56 -05:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2017-12-15 16:11:02 -05:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
|
2017-06-02 22:46:56 -05:00
|
|
|
"github.com/stretchr/testify/assert"
|
2019-08-23 11:40:30 -05:00
|
|
|
"github.com/unknwon/i18n"
|
2017-06-02 22:46:56 -05:00
|
|
|
)
|
|
|
|
|
2017-06-29 10:11:38 -05: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 14:36:47 -05:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 10:11:38 -05:00
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
|
|
|
|
link, exists := htmlDoc.doc.Find("form").Attr("action")
|
|
|
|
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)
|
|
|
|
|
2017-07-07 14:36:47 -05:00
|
|
|
resp = session.MakeRequest(t, req, http.StatusFound)
|
2017-06-29 10:11:38 -05:00
|
|
|
|
2017-12-15 16:11:02 -05:00
|
|
|
test.RedirectURL(resp) // check that redirect URL exists
|
2017-06-29 10:11:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func checkLatestReleaseAndCount(t *testing.T, session *TestSession, repoURL, version, label string, count int) {
|
|
|
|
req := NewRequest(t, "GET", repoURL+"/releases")
|
2017-07-07 14:36:47 -05:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
|
|
|
labelText := htmlDoc.doc.Find("#release-list > li .meta .label").First().Text()
|
|
|
|
assert.EqualValues(t, label, labelText)
|
|
|
|
titleText := htmlDoc.doc.Find("#release-list > li .detail h3 a").First().Text()
|
|
|
|
assert.EqualValues(t, version, titleText)
|
|
|
|
|
|
|
|
releaseList := htmlDoc.doc.Find("#release-list > li")
|
|
|
|
assert.EqualValues(t, count, releaseList.Length())
|
|
|
|
}
|
|
|
|
|
2017-06-02 22:46:56 -05:00
|
|
|
func TestViewReleases(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-02 22:46:56 -05:00
|
|
|
|
2017-06-16 23:49:45 -05:00
|
|
|
session := loginUser(t, "user2")
|
2017-06-09 19:41:36 -05:00
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 14:36:47 -05:00
|
|
|
session.MakeRequest(t, req, http.StatusOK)
|
2017-06-02 22:46:56 -05:00
|
|
|
}
|
2017-06-17 22:38:24 -05:00
|
|
|
|
|
|
|
func TestViewReleasesNoLogin(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-17 22:38:24 -05:00
|
|
|
|
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/releases")
|
2017-07-07 14:36:47 -05:00
|
|
|
MakeRequest(t, req, http.StatusOK)
|
2017-06-17 22:38:24 -05:00
|
|
|
}
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
func TestCreateRelease(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, false)
|
|
|
|
|
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.stable"), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleasePreRelease(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", true, false)
|
|
|
|
|
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.prerelease"), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleaseDraft(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
createNewRelease(t, session, "/user2/repo1", "v0.0.1", "v0.0.1", false, true)
|
|
|
|
|
|
|
|
checkLatestReleaseAndCount(t, session, "/user2/repo1", "v0.0.1", i18n.Tr("en", "repo.release.draft"), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateReleasePaging(t *testing.T) {
|
2019-11-25 18:21:37 -05:00
|
|
|
defer prepareTestEnv(t)()
|
2017-06-29 10:11:38 -05:00
|
|
|
|
|
|
|
session := loginUser(t, "user2")
|
|
|
|
// Create enaugh releases to have paging
|
|
|
|
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 02:19:28 -05:00
|
|
|
// Check that user4 does not see draft and still see 10 latest releases
|
|
|
|
session2 := loginUser(t, "user4")
|
2017-06-29 10:11:38 -05:00
|
|
|
checkLatestReleaseAndCount(t, session2, "/user2/repo1", "v0.0.11", i18n.Tr("en", "repo.release.stable"), 10)
|
|
|
|
}
|