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.

issue_test.go 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  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. }