本站源代码
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.

73 lines
2.1KB

  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 models
  5. import (
  6. "testing"
  7. "code.gitea.io/gitea/modules/setting"
  8. "github.com/stretchr/testify/assert"
  9. )
  10. func TestIssueList_LoadRepositories(t *testing.T) {
  11. assert.NoError(t, PrepareTestDatabase())
  12. issueList := IssueList{
  13. AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
  14. AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
  15. AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
  16. }
  17. repos, err := issueList.LoadRepositories()
  18. assert.NoError(t, err)
  19. assert.Len(t, repos, 2)
  20. for _, issue := range issueList {
  21. assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
  22. }
  23. }
  24. func TestIssueList_LoadAttributes(t *testing.T) {
  25. assert.NoError(t, PrepareTestDatabase())
  26. setting.Service.EnableTimetracking = true
  27. issueList := IssueList{
  28. AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
  29. AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
  30. AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
  31. }
  32. assert.NoError(t, issueList.LoadAttributes())
  33. for _, issue := range issueList {
  34. assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
  35. for _, label := range issue.Labels {
  36. assert.EqualValues(t, issue.RepoID, label.RepoID)
  37. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
  38. }
  39. if issue.PosterID > 0 {
  40. assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
  41. }
  42. if issue.AssigneeID > 0 {
  43. assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
  44. }
  45. if issue.MilestoneID > 0 {
  46. assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
  47. }
  48. if issue.IsPull {
  49. assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
  50. }
  51. for _, attachment := range issue.Attachments {
  52. assert.EqualValues(t, issue.ID, attachment.IssueID)
  53. }
  54. for _, comment := range issue.Comments {
  55. assert.EqualValues(t, issue.ID, comment.IssueID)
  56. }
  57. if issue.ID == int64(1) {
  58. assert.Equal(t, int64(400), issue.TotalTrackedTime)
  59. } else if issue.ID == int64(2) {
  60. assert.Equal(t, int64(3662), issue.TotalTrackedTime)
  61. }
  62. }
  63. }
上海开阖软件有限公司 沪ICP备12045867号-1