gitea源码

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright 2025 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package issue
  4. import (
  5. "testing"
  6. repo_model "code.gitea.io/gitea/models/repo"
  7. "code.gitea.io/gitea/models/unittest"
  8. "code.gitea.io/gitea/modules/optional"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. func Test_Suggestion(t *testing.T) {
  12. assert.NoError(t, unittest.PrepareTestDatabase())
  13. repo1 := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
  14. testCases := []struct {
  15. keyword string
  16. isPull optional.Option[bool]
  17. expectedIndexes []int64
  18. }{
  19. {
  20. keyword: "",
  21. expectedIndexes: []int64{5, 1, 4, 2, 3},
  22. },
  23. {
  24. keyword: "1",
  25. expectedIndexes: []int64{1},
  26. },
  27. {
  28. keyword: "issue",
  29. expectedIndexes: []int64{4, 1, 2, 3},
  30. },
  31. {
  32. keyword: "pull",
  33. expectedIndexes: []int64{5},
  34. },
  35. }
  36. for _, testCase := range testCases {
  37. t.Run(testCase.keyword, func(t *testing.T) {
  38. issues, err := GetSuggestion(t.Context(), repo1, testCase.isPull, testCase.keyword)
  39. assert.NoError(t, err)
  40. issueIndexes := make([]int64, 0, len(issues))
  41. for _, issue := range issues {
  42. issueIndexes = append(issueIndexes, issue.Index)
  43. }
  44. assert.Equal(t, testCase.expectedIndexes, issueIndexes)
  45. })
  46. }
  47. }