本站源代码
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

127 lines
3.3KB

  1. // Copyright 2019 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 repofiles
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/models"
  8. "code.gitea.io/gitea/modules/git"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func testCorrectRepoAction(t *testing.T, opts CommitRepoActionOptions, actionBean *models.Action) {
  12. models.AssertNotExistsBean(t, actionBean)
  13. assert.NoError(t, CommitRepoAction(opts))
  14. models.AssertExistsAndLoadBean(t, actionBean)
  15. models.CheckConsistencyFor(t, &models.Action{})
  16. }
  17. func TestCommitRepoAction(t *testing.T) {
  18. samples := []struct {
  19. userID int64
  20. repositoryID int64
  21. commitRepoActionOptions CommitRepoActionOptions
  22. action models.Action
  23. }{
  24. {
  25. userID: 2,
  26. repositoryID: 16,
  27. commitRepoActionOptions: CommitRepoActionOptions{
  28. RefFullName: "refName",
  29. OldCommitID: "oldCommitID",
  30. NewCommitID: "newCommitID",
  31. Commits: &models.PushCommits{
  32. Commits: []*models.PushCommit{
  33. {
  34. Sha1: "69554a6",
  35. CommitterEmail: "user2@example.com",
  36. CommitterName: "User2",
  37. AuthorEmail: "user2@example.com",
  38. AuthorName: "User2",
  39. Message: "not signed commit",
  40. },
  41. {
  42. Sha1: "27566bd",
  43. CommitterEmail: "user2@example.com",
  44. CommitterName: "User2",
  45. AuthorEmail: "user2@example.com",
  46. AuthorName: "User2",
  47. Message: "good signed commit (with not yet validated email)",
  48. },
  49. },
  50. Len: 2,
  51. },
  52. },
  53. action: models.Action{
  54. OpType: models.ActionCommitRepo,
  55. RefName: "refName",
  56. },
  57. },
  58. {
  59. userID: 2,
  60. repositoryID: 1,
  61. commitRepoActionOptions: CommitRepoActionOptions{
  62. RefFullName: git.TagPrefix + "v1.1",
  63. OldCommitID: git.EmptySHA,
  64. NewCommitID: "newCommitID",
  65. Commits: &models.PushCommits{},
  66. },
  67. action: models.Action{
  68. OpType: models.ActionPushTag,
  69. RefName: "v1.1",
  70. },
  71. },
  72. {
  73. userID: 2,
  74. repositoryID: 1,
  75. commitRepoActionOptions: CommitRepoActionOptions{
  76. RefFullName: git.TagPrefix + "v1.1",
  77. OldCommitID: "oldCommitID",
  78. NewCommitID: git.EmptySHA,
  79. Commits: &models.PushCommits{},
  80. },
  81. action: models.Action{
  82. OpType: models.ActionDeleteTag,
  83. RefName: "v1.1",
  84. },
  85. },
  86. {
  87. userID: 2,
  88. repositoryID: 1,
  89. commitRepoActionOptions: CommitRepoActionOptions{
  90. RefFullName: git.BranchPrefix + "feature/1",
  91. OldCommitID: "oldCommitID",
  92. NewCommitID: git.EmptySHA,
  93. Commits: &models.PushCommits{},
  94. },
  95. action: models.Action{
  96. OpType: models.ActionDeleteBranch,
  97. RefName: "feature/1",
  98. },
  99. },
  100. }
  101. for _, s := range samples {
  102. models.PrepareTestEnv(t)
  103. user := models.AssertExistsAndLoadBean(t, &models.User{ID: s.userID}).(*models.User)
  104. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: s.repositoryID, OwnerID: user.ID}).(*models.Repository)
  105. repo.Owner = user
  106. s.commitRepoActionOptions.PusherName = user.Name
  107. s.commitRepoActionOptions.RepoOwnerID = user.ID
  108. s.commitRepoActionOptions.RepoName = repo.Name
  109. s.action.ActUserID = user.ID
  110. s.action.RepoID = repo.ID
  111. s.action.Repo = repo
  112. s.action.IsPrivate = repo.IsPrivate
  113. testCorrectRepoAction(t, s.commitRepoActionOptions, &s.action)
  114. }
  115. }
上海开阖软件有限公司 沪ICP备12045867号-1