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.

103 lines
2.7 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 release
  5. import (
  6. "path/filepath"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. "code.gitea.io/gitea/modules/git"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestMain(m *testing.M) {
  13. models.MainTest(m, filepath.Join("..", ".."))
  14. }
  15. func TestRelease_Create(t *testing.T) {
  16. assert.NoError(t, models.PrepareTestDatabase())
  17. user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
  18. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  19. repoPath := models.RepoPath(user.Name, repo.Name)
  20. gitRepo, err := git.OpenRepository(repoPath)
  21. assert.NoError(t, err)
  22. defer gitRepo.Close()
  23. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  24. RepoID: repo.ID,
  25. PublisherID: user.ID,
  26. TagName: "v0.1",
  27. Target: "master",
  28. Title: "v0.1 is released",
  29. Note: "v0.1 is released",
  30. IsDraft: false,
  31. IsPrerelease: false,
  32. IsTag: false,
  33. }, nil))
  34. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  35. RepoID: repo.ID,
  36. PublisherID: user.ID,
  37. TagName: "v0.1.1",
  38. Target: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
  39. Title: "v0.1.1 is released",
  40. Note: "v0.1.1 is released",
  41. IsDraft: false,
  42. IsPrerelease: false,
  43. IsTag: false,
  44. }, nil))
  45. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  46. RepoID: repo.ID,
  47. PublisherID: user.ID,
  48. TagName: "v0.1.2",
  49. Target: "65f1bf2",
  50. Title: "v0.1.2 is released",
  51. Note: "v0.1.2 is released",
  52. IsDraft: false,
  53. IsPrerelease: false,
  54. IsTag: false,
  55. }, nil))
  56. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  57. RepoID: repo.ID,
  58. PublisherID: user.ID,
  59. TagName: "v0.1.3",
  60. Target: "65f1bf2",
  61. Title: "v0.1.3 is released",
  62. Note: "v0.1.3 is released",
  63. IsDraft: true,
  64. IsPrerelease: false,
  65. IsTag: false,
  66. }, nil))
  67. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  68. RepoID: repo.ID,
  69. PublisherID: user.ID,
  70. TagName: "v0.1.4",
  71. Target: "65f1bf2",
  72. Title: "v0.1.4 is released",
  73. Note: "v0.1.4 is released",
  74. IsDraft: false,
  75. IsPrerelease: true,
  76. IsTag: false,
  77. }, nil))
  78. assert.NoError(t, CreateRelease(gitRepo, &models.Release{
  79. RepoID: repo.ID,
  80. PublisherID: user.ID,
  81. TagName: "v0.1.5",
  82. Target: "65f1bf2",
  83. Title: "v0.1.5 is released",
  84. Note: "v0.1.5 is released",
  85. IsDraft: false,
  86. IsPrerelease: false,
  87. IsTag: true,
  88. }, nil))
  89. }