本站源代码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

72 linhas
1.7KB

  1. // Copyright 2019 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 issues
  5. import (
  6. "os"
  7. "path/filepath"
  8. "testing"
  9. "time"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/setting"
  12. "github.com/stretchr/testify/assert"
  13. )
  14. func TestMain(m *testing.M) {
  15. models.MainTest(m, filepath.Join("..", "..", ".."))
  16. }
  17. func TestBleveSearchIssues(t *testing.T) {
  18. assert.NoError(t, models.PrepareTestDatabase())
  19. os.RemoveAll(setting.Indexer.IssueQueueDir)
  20. os.RemoveAll(setting.Indexer.IssuePath)
  21. setting.Indexer.IssueType = "bleve"
  22. InitIssueIndexer(true)
  23. time.Sleep(5 * time.Second)
  24. ids, err := SearchIssuesByKeyword(1, "issue2")
  25. assert.NoError(t, err)
  26. assert.EqualValues(t, []int64{2}, ids)
  27. ids, err = SearchIssuesByKeyword(1, "first")
  28. assert.NoError(t, err)
  29. assert.EqualValues(t, []int64{1}, ids)
  30. ids, err = SearchIssuesByKeyword(1, "for")
  31. assert.NoError(t, err)
  32. assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
  33. ids, err = SearchIssuesByKeyword(1, "good")
  34. assert.NoError(t, err)
  35. assert.EqualValues(t, []int64{1}, ids)
  36. }
  37. func TestDBSearchIssues(t *testing.T) {
  38. assert.NoError(t, models.PrepareTestDatabase())
  39. setting.Indexer.IssueType = "db"
  40. InitIssueIndexer(true)
  41. ids, err := SearchIssuesByKeyword(1, "issue2")
  42. assert.NoError(t, err)
  43. assert.EqualValues(t, []int64{2}, ids)
  44. ids, err = SearchIssuesByKeyword(1, "first")
  45. assert.NoError(t, err)
  46. assert.EqualValues(t, []int64{1}, ids)
  47. ids, err = SearchIssuesByKeyword(1, "for")
  48. assert.NoError(t, err)
  49. assert.EqualValues(t, []int64{1, 2, 3, 5}, ids)
  50. ids, err = SearchIssuesByKeyword(1, "good")
  51. assert.NoError(t, err)
  52. assert.EqualValues(t, []int64{1}, ids)
  53. }
上海开阖软件有限公司 沪ICP备12045867号-1