-
Notifications
You must be signed in to change notification settings - Fork 26
/
feeds_test.go
58 lines (49 loc) · 1.33 KB
/
feeds_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package main
import (
"context"
"net/http"
"testing"
"github.com/carlmjohnson/requests"
"github.com/mmcdole/gofeed"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func Test_feeds(t *testing.T) {
app := &goBlog{
cfg: createDefaultTestConfig(t),
}
_ = app.initConfig(false)
app.initMarkdown()
_ = app.initTemplateStrings()
_ = app.initCache()
app.initSessions()
app.d = app.buildRouter()
handlerClient := newHandlerClient(app.d)
err := app.createPost(&post{
Path: "/testpost",
Section: "posts",
Status: "published",
Published: "2020-01-01T00:00:00Z",
Parameters: map[string][]string{"title": {"Test Post"}},
Content: "Test Content",
})
require.NoError(t, err)
for _, typ := range []feedType{rssFeed, atomFeed, jsonFeed} {
var feed *gofeed.Feed
err := requests.URL("http://localhost:8080/posts." + string(typ)).Client(handlerClient).
Handle(func(r *http.Response) (err error) {
fp := gofeed.NewParser()
defer r.Body.Close()
feed, err = fp.Parse(r.Body)
return
}).
Fetch(context.Background())
require.NoError(t, err)
require.NotNil(t, feed)
assert.Equal(t, string(typ), feed.FeedType)
if assert.Len(t, feed.Items, 1) {
assert.Equal(t, "Test Post", feed.Items[0].Title)
assert.Equal(t, "Test Content", feed.Items[0].Description)
}
}
}