You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.3 KiB

  1. // Copyright 2018 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. "code.gitea.io/git"
  10. "code.gitea.io/gitea/models"
  11. api "code.gitea.io/sdk/gitea"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestAPICreateRelease(t *testing.T) {
  15. prepareTestEnv(t)
  16. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  17. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  18. session := loginUser(t, owner.LowerName)
  19. gitRepo, err := git.OpenRepository(repo.RepoPath())
  20. assert.NoError(t, err)
  21. err = gitRepo.CreateTag("v0.0.1", "master")
  22. assert.NoError(t, err)
  23. commitID, err := gitRepo.GetTagCommitID("v0.0.1")
  24. assert.NoError(t, err)
  25. urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/releases",
  26. owner.Name, repo.Name)
  27. req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateReleaseOption{
  28. TagName: "v0.0.1",
  29. Title: "v0.0.1",
  30. Note: "test",
  31. IsDraft: false,
  32. IsPrerelease: false,
  33. Target: commitID,
  34. })
  35. resp := session.MakeRequest(t, req, http.StatusCreated)
  36. var newRelease api.Release
  37. DecodeJSON(t, resp, &newRelease)
  38. models.AssertExistsAndLoadBean(t, &models.Release{
  39. ID: newRelease.ID,
  40. TagName: newRelease.TagName,
  41. Title: newRelease.Title,
  42. Note: newRelease.Note,
  43. })
  44. urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/releases/%d",
  45. owner.Name, repo.Name, newRelease.ID)
  46. req = NewRequest(t, "GET", urlStr)
  47. resp = session.MakeRequest(t, req, http.StatusOK)
  48. var release api.Release
  49. DecodeJSON(t, resp, &release)
  50. assert.Equal(t, newRelease.TagName, release.TagName)
  51. assert.Equal(t, newRelease.Title, release.Title)
  52. assert.Equal(t, newRelease.Note, release.Note)
  53. req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditReleaseOption{
  54. TagName: release.TagName,
  55. Title: release.Title,
  56. Note: "updated",
  57. IsDraft: &release.IsDraft,
  58. IsPrerelease: &release.IsPrerelease,
  59. Target: release.Target,
  60. })
  61. resp = session.MakeRequest(t, req, http.StatusOK)
  62. DecodeJSON(t, resp, &newRelease)
  63. models.AssertExistsAndLoadBean(t, &models.Release{
  64. ID: newRelease.ID,
  65. TagName: newRelease.TagName,
  66. Title: newRelease.Title,
  67. Note: newRelease.Note,
  68. })
  69. }