summaryrefslogtreecommitdiffstats
path: root/integrations/api_releases_test.go
diff options
context:
space:
mode:
authorJohan Van de Wauw <johan@gisky.be>2020-09-25 21:11:43 +0200
committerGitHub <noreply@github.com>2020-09-25 20:11:43 +0100
commit34d9cb335c08da785b90acb2c1001b93218f6ac2 (patch)
tree71ad09ed927a79b891b857e97d4e43e506a6763d /integrations/api_releases_test.go
parentd71eaacbf2ff9f97c3577ad9e3a9092f0fdab3ec (diff)
downloadgitea-34d9cb335c08da785b90acb2c1001b93218f6ac2.tar.gz
gitea-34d9cb335c08da785b90acb2c1001b93218f6ac2.zip
API: Get release by tags endpoint (#12932)
Get a release based on a tag name (for which a release exists). Based on: https://developer.github.com/v3/repos/releases/#get-a-release-by-tag-name Co-authored-by: 赵智超 <1012112796@qq.com> Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'integrations/api_releases_test.go')
-rw-r--r--integrations/api_releases_test.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go
index 9aef33d068..58c2e35440 100644
--- a/integrations/api_releases_test.go
+++ b/integrations/api_releases_test.go
@@ -7,6 +7,7 @@ package integrations
import (
"fmt"
"net/http"
+ "strings"
"testing"
"code.gitea.io/gitea/models"
@@ -120,3 +121,36 @@ func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) {
createNewReleaseUsingAPI(t, session, token, owner, repo, "v0.0.1", "", "v0.0.1", "test")
}
+
+func TestAPIGetReleaseByTag(t *testing.T) {
+ defer prepareTestEnv(t)()
+
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ session := loginUser(t, owner.LowerName)
+
+ tag := "v1.1"
+
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s/",
+ owner.Name, repo.Name, tag)
+
+ req := NewRequestf(t, "GET", urlStr)
+ resp := session.MakeRequest(t, req, http.StatusOK)
+
+ var release *api.Release
+ DecodeJSON(t, resp, &release)
+
+ assert.Equal(t, "testing-release", release.Title)
+
+ nonexistingtag := "nonexistingtag"
+
+ urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/releases/tags/%s/",
+ owner.Name, repo.Name, nonexistingtag)
+
+ req = NewRequestf(t, "GET", urlStr)
+ resp = session.MakeRequest(t, req, http.StatusNotFound)
+
+ var err *api.APIError
+ DecodeJSON(t, resp, &err)
+ assert.True(t, strings.HasPrefix(err.Message, "release tag does not exist"))
+}