diff options
author | Lauris BH <lauris@nix.lv> | 2019-01-30 18:33:00 +0200 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-01-30 11:33:00 -0500 |
commit | fada6968a847f628a6d32ac546e1228838809498 (patch) | |
tree | b0f8c8cd14a5c6e7bbffbc170e52527865a58462 /integrations/api_releases_test.go | |
parent | 8b5f6ced22d510a399bf304915ad77c61d6ce7b3 (diff) | |
download | gitea-fada6968a847f628a6d32ac546e1228838809498.tar.gz gitea-fada6968a847f628a6d32ac546e1228838809498.zip |
Fix new release creation API to allow empty target (#5870)
* Fix new release creation API to allow empty target
* Add more test cases
* Update swagger
Diffstat (limited to 'integrations/api_releases_test.go')
-rw-r--r-- | integrations/api_releases_test.go | 81 |
1 files changed, 58 insertions, 23 deletions
diff --git a/integrations/api_releases_test.go b/integrations/api_releases_test.go index c8bad51c09..5c1b6c5d49 100644 --- a/integrations/api_releases_test.go +++ b/integrations/api_releases_test.go @@ -16,31 +16,16 @@ import ( "github.com/stretchr/testify/assert" ) -func TestAPICreateRelease(t *testing.T) { - 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) - token := getTokenForLoggedInUser(t, session) - gitRepo, err := git.OpenRepository(repo.RepoPath()) - assert.NoError(t, err) - - err = gitRepo.CreateTag("v0.0.1", "master") - assert.NoError(t, err) - - commitID, err := gitRepo.GetTagCommitID("v0.0.1") - assert.NoError(t, err) - +func createNewReleaseUsingAPI(t *testing.T, session *TestSession, token string, owner *models.User, repo *models.Repository, name, target, title, desc string) *api.Release { urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases?token=%s", owner.Name, repo.Name, token) req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{ - TagName: "v0.0.1", - Title: "v0.0.1", - Note: "test", + TagName: name, + Title: title, + Note: desc, IsDraft: false, IsPrerelease: false, - Target: commitID, + Target: target, }) resp := session.MakeRequest(t, req, http.StatusCreated) @@ -53,10 +38,32 @@ func TestAPICreateRelease(t *testing.T) { Note: newRelease.Note, }) - urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d?token=%s", + return &newRelease +} + +func TestAPICreateAndUpdateRelease(t *testing.T) { + 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) + token := getTokenForLoggedInUser(t, session) + + gitRepo, err := git.OpenRepository(repo.RepoPath()) + assert.NoError(t, err) + + err = gitRepo.CreateTag("v0.0.1", "master") + assert.NoError(t, err) + + target, err := gitRepo.GetTagCommitID("v0.0.1") + assert.NoError(t, err) + + newRelease := createNewReleaseUsingAPI(t, session, token, owner, repo, "v0.0.1", target, "v0.0.1", "test") + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d?token=%s", owner.Name, repo.Name, newRelease.ID, token) - req = NewRequest(t, "GET", urlStr) - resp = session.MakeRequest(t, req, http.StatusOK) + req := NewRequest(t, "GET", urlStr) + resp := session.MakeRequest(t, req, http.StatusOK) var release api.Release DecodeJSON(t, resp, &release) @@ -83,3 +90,31 @@ func TestAPICreateRelease(t *testing.T) { Note: newRelease.Note, }) } + +func TestAPICreateReleaseToDefaultBranch(t *testing.T) { + 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) + token := getTokenForLoggedInUser(t, session) + + createNewReleaseUsingAPI(t, session, token, owner, repo, "v0.0.1", "", "v0.0.1", "test") +} + +func TestAPICreateReleaseToDefaultBranchOnExistingTag(t *testing.T) { + 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) + token := getTokenForLoggedInUser(t, session) + + gitRepo, err := git.OpenRepository(repo.RepoPath()) + assert.NoError(t, err) + + err = gitRepo.CreateTag("v0.0.1", "master") + assert.NoError(t, err) + + createNewReleaseUsingAPI(t, session, token, owner, repo, "v0.0.1", "", "v0.0.1", "test") +} |