gitea源码

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright 2022 The Gitea Authors. All rights reserved.
  2. // SPDX-License-Identifier: MIT
  3. package integration
  4. import (
  5. "encoding/xml"
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/tests"
  9. "github.com/stretchr/testify/assert"
  10. )
  11. // RSS is a struct to unmarshal RSS feeds test only
  12. type RSS struct {
  13. Channel struct {
  14. Title string `xml:"title"`
  15. Link string `xml:"link"`
  16. Description string `xml:"description"`
  17. PubDate string `xml:"pubDate"`
  18. Items []struct {
  19. Title string `xml:"title"`
  20. Link string `xml:"link"`
  21. Description string `xml:"description"`
  22. PubDate string `xml:"pubDate"`
  23. } `xml:"item"`
  24. } `xml:"channel"`
  25. }
  26. func TestFeedUser(t *testing.T) {
  27. t.Run("User", func(t *testing.T) {
  28. t.Run("Atom", func(t *testing.T) {
  29. defer tests.PrepareTestEnv(t)()
  30. req := NewRequest(t, "GET", "/user2.atom")
  31. resp := MakeRequest(t, req, http.StatusOK)
  32. data := resp.Body.String()
  33. assert.Contains(t, data, `<feed xmlns="http://www.w3.org/2005/Atom"`)
  34. })
  35. t.Run("RSS", func(t *testing.T) {
  36. defer tests.PrepareTestEnv(t)()
  37. req := NewRequest(t, "GET", "/user2.rss")
  38. resp := MakeRequest(t, req, http.StatusOK)
  39. data := resp.Body.String()
  40. assert.Contains(t, data, `<rss version="2.0"`)
  41. var rss RSS
  42. err := xml.Unmarshal(resp.Body.Bytes(), &rss)
  43. assert.NoError(t, err)
  44. assert.Contains(t, rss.Channel.Link, "/user2")
  45. assert.NotEmpty(t, rss.Channel.PubDate)
  46. })
  47. })
  48. }