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.

57 lines
1.3 KiB

  1. // Copyright 2018 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 TestAddTopic(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. topics, err := FindTopics(&FindTopicOptions{})
  12. assert.NoError(t, err)
  13. assert.EqualValues(t, 3, len(topics))
  14. topics, err = FindTopics(&FindTopicOptions{
  15. Limit: 2,
  16. })
  17. assert.NoError(t, err)
  18. assert.EqualValues(t, 2, len(topics))
  19. topics, err = FindTopics(&FindTopicOptions{
  20. RepoID: 1,
  21. })
  22. assert.NoError(t, err)
  23. assert.EqualValues(t, 3, len(topics))
  24. assert.NoError(t, SaveTopics(2, "golang"))
  25. topics, err = FindTopics(&FindTopicOptions{})
  26. assert.NoError(t, err)
  27. assert.EqualValues(t, 3, len(topics))
  28. topics, err = FindTopics(&FindTopicOptions{
  29. RepoID: 2,
  30. })
  31. assert.NoError(t, err)
  32. assert.EqualValues(t, 1, len(topics))
  33. assert.NoError(t, SaveTopics(2, "golang", "gitea"))
  34. topic, err := GetTopicByName("gitea")
  35. assert.NoError(t, err)
  36. assert.EqualValues(t, 1, topic.RepoCount)
  37. topics, err = FindTopics(&FindTopicOptions{})
  38. assert.NoError(t, err)
  39. assert.EqualValues(t, 4, len(topics))
  40. topics, err = FindTopics(&FindTopicOptions{
  41. RepoID: 2,
  42. })
  43. assert.NoError(t, err)
  44. assert.EqualValues(t, 2, len(topics))
  45. }