Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

repo_topic_test.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright 2022 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 integrations
  5. import (
  6. "net/http"
  7. "net/url"
  8. "testing"
  9. api "code.gitea.io/gitea/modules/structs"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestTopicSearch(t *testing.T) {
  13. defer prepareTestEnv(t)()
  14. searchURL, _ := url.Parse("/explore/topics/search")
  15. var topics struct {
  16. TopicNames []*api.TopicResponse `json:"topics"`
  17. }
  18. query := url.Values{"page": []string{"1"}, "limit": []string{"4"}}
  19. searchURL.RawQuery = query.Encode()
  20. res := MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
  21. DecodeJSON(t, res, &topics)
  22. assert.Len(t, topics.TopicNames, 4)
  23. assert.EqualValues(t, "6", res.Header().Get("x-total-count"))
  24. query.Add("q", "topic")
  25. searchURL.RawQuery = query.Encode()
  26. res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
  27. DecodeJSON(t, res, &topics)
  28. assert.Len(t, topics.TopicNames, 2)
  29. query.Set("q", "database")
  30. searchURL.RawQuery = query.Encode()
  31. res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
  32. DecodeJSON(t, res, &topics)
  33. if assert.Len(t, topics.TopicNames, 1) {
  34. assert.EqualValues(t, 2, topics.TopicNames[0].ID)
  35. assert.EqualValues(t, "database", topics.TopicNames[0].Name)
  36. assert.EqualValues(t, 1, topics.TopicNames[0].RepoCount)
  37. }
  38. }