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.

63 lines
1.4 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 TestSearchRepositoryByName(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. // test search public repository on explore page
  12. repos, count, err := SearchRepositoryByName(&SearchRepoOptions{
  13. Keyword: "repo_12",
  14. Page: 1,
  15. PageSize: 10,
  16. Searcher: nil,
  17. })
  18. assert.NotNil(t, repos)
  19. assert.NoError(t, err)
  20. assert.Equal(t, "test_repo_12", repos[0].Name)
  21. assert.Equal(t, int64(1), count)
  22. repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
  23. Keyword: "test_repo",
  24. Page: 1,
  25. PageSize: 10,
  26. Searcher: nil,
  27. })
  28. assert.NotNil(t, repos)
  29. assert.NoError(t, err)
  30. assert.Equal(t, int64(2), count)
  31. // test search private repository on explore page
  32. repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
  33. Keyword: "repo_13",
  34. Page: 1,
  35. PageSize: 10,
  36. Searcher: &User{ID: 14},
  37. })
  38. assert.NotNil(t, repos)
  39. assert.NoError(t, err)
  40. assert.Equal(t, "test_repo_13", repos[0].Name)
  41. assert.Equal(t, int64(1), count)
  42. repos, count, err = SearchRepositoryByName(&SearchRepoOptions{
  43. Keyword: "test_repo",
  44. Page: 1,
  45. PageSize: 10,
  46. Searcher: &User{ID: 14},
  47. })
  48. assert.NotNil(t, repos)
  49. assert.NoError(t, err)
  50. assert.Equal(t, int64(3), count)
  51. }