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.

62 lines
1.4 KiB

  1. // Copyright 2017 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 repo
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/auth"
  9. "code.gitea.io/gitea/modules/test"
  10. )
  11. func TestNewReleasePost(t *testing.T) {
  12. for _, testCase := range []struct {
  13. RepoID int64
  14. UserID int64
  15. TagName string
  16. Form auth.NewReleaseForm
  17. }{
  18. {
  19. RepoID: 1,
  20. UserID: 2,
  21. TagName: "v1.1", // pre-existing tag
  22. Form: auth.NewReleaseForm{
  23. TagName: "newtag",
  24. Target: "master",
  25. Title: "title",
  26. Content: "content",
  27. },
  28. },
  29. {
  30. RepoID: 1,
  31. UserID: 2,
  32. TagName: "newtag",
  33. Form: auth.NewReleaseForm{
  34. TagName: "newtag",
  35. Target: "master",
  36. Title: "title",
  37. Content: "content",
  38. },
  39. },
  40. } {
  41. models.PrepareTestEnv(t)
  42. ctx := test.MockContext(t, "user2/repo1/releases/new")
  43. test.LoadUser(t, ctx, 2)
  44. test.LoadRepo(t, ctx, 1)
  45. test.LoadGitRepo(t, ctx)
  46. NewReleasePost(ctx, testCase.Form)
  47. models.AssertExistsAndLoadBean(t, &models.Release{
  48. RepoID: 1,
  49. PublisherID: 2,
  50. TagName: testCase.Form.TagName,
  51. Target: testCase.Form.Target,
  52. Title: testCase.Form.Title,
  53. Note: testCase.Form.Content,
  54. }, models.Cond("is_draft=?", len(testCase.Form.Draft) > 0))
  55. ctx.Repo.GitRepo.Close()
  56. }
  57. }