mirror of https://github.com/jlelse/GoBlog
Simple blogging system written in Go
https://goblog.app
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.
55 lines
1.3 KiB
55 lines
1.3 KiB
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() |
|
_ = app.initDatabase(false) |
|
defer app.db.close() |
|
app.initComponents(false) |
|
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) |
|
} |
|
} |
|
}
|
|
|