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.

65 lines
1.8 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 models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestIssueList_LoadRepositories(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. issueList := IssueList{
  12. AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
  13. AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
  14. AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
  15. }
  16. repos, err := issueList.LoadRepositories()
  17. assert.NoError(t, err)
  18. assert.Len(t, repos, 2)
  19. for _, issue := range issueList {
  20. assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
  21. }
  22. }
  23. func TestIssueList_LoadAttributes(t *testing.T) {
  24. assert.NoError(t, PrepareTestDatabase())
  25. issueList := IssueList{
  26. AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue),
  27. AssertExistsAndLoadBean(t, &Issue{ID: 2}).(*Issue),
  28. AssertExistsAndLoadBean(t, &Issue{ID: 4}).(*Issue),
  29. }
  30. assert.NoError(t, issueList.LoadAttributes())
  31. for _, issue := range issueList {
  32. assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
  33. for _, label := range issue.Labels {
  34. assert.EqualValues(t, issue.RepoID, label.RepoID)
  35. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issue.ID, LabelID: label.ID})
  36. }
  37. if issue.PosterID > 0 {
  38. assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
  39. }
  40. if issue.AssigneeID > 0 {
  41. assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
  42. }
  43. if issue.MilestoneID > 0 {
  44. assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
  45. }
  46. if issue.IsPull {
  47. assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
  48. }
  49. for _, attachment := range issue.Attachments {
  50. assert.EqualValues(t, issue.ID, attachment.IssueID)
  51. }
  52. for _, comment := range issue.Comments {
  53. assert.EqualValues(t, issue.ID, comment.IssueID)
  54. }
  55. }
  56. }