You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

issue_test.go 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 TestIssue_ReplaceLabels(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. testSuccess := func(issueID int64, labelIDs []int64) {
  12. issue := AssertExistsAndLoadBean(t, &Issue{ID: issueID}).(*Issue)
  13. repo := AssertExistsAndLoadBean(t, &Repository{ID: issue.RepoID}).(*Repository)
  14. doer := AssertExistsAndLoadBean(t, &User{ID: repo.OwnerID}).(*User)
  15. labels := make([]*Label, len(labelIDs))
  16. for i, labelID := range labelIDs {
  17. labels[i] = AssertExistsAndLoadBean(t, &Label{ID: labelID, RepoID: repo.ID}).(*Label)
  18. }
  19. assert.NoError(t, issue.ReplaceLabels(labels, doer))
  20. AssertCount(t, &IssueLabel{IssueID: issueID}, len(labelIDs))
  21. for _, labelID := range labelIDs {
  22. AssertExistsAndLoadBean(t, &IssueLabel{IssueID: issueID, LabelID: labelID})
  23. }
  24. }
  25. testSuccess(1, []int64{2})
  26. testSuccess(1, []int64{1, 2})
  27. testSuccess(1, []int64{})
  28. }
  29. func TestIssueAPIURL(t *testing.T) {
  30. assert.NoError(t, PrepareTestDatabase())
  31. issue := AssertExistsAndLoadBean(t, &Issue{ID: 1}).(*Issue)
  32. err := issue.LoadAttributes()
  33. assert.NoError(t, err)
  34. assert.Equal(t, "https://try.gitea.io/api/v1/repos/user2/repo1/issues/1", issue.APIURL())
  35. }
  36. func TestGetIssuesByIDs(t *testing.T) {
  37. assert.NoError(t, PrepareTestDatabase())
  38. testSuccess := func(expectedIssueIDs []int64, nonExistentIssueIDs []int64) {
  39. issues, err := GetIssuesByIDs(append(expectedIssueIDs, nonExistentIssueIDs...))
  40. assert.NoError(t, err)
  41. actualIssueIDs := make([]int64, len(issues))
  42. for i, issue := range issues {
  43. actualIssueIDs[i] = issue.ID
  44. }
  45. assert.Equal(t, expectedIssueIDs, actualIssueIDs)
  46. }
  47. testSuccess([]int64{1, 2, 3}, []int64{})
  48. testSuccess([]int64{1, 2, 3}, []int64{NonexistentID})
  49. }