Simple blogging system written in Go
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.

96 lines
2.3 KiB

package main
import (
func Test_blogroll(t *testing.T) {
fc := newFakeHttpClient()
app := &goBlog{
httpClient: fc.Client,
cfg: &config{
Db: &configDb{
File: filepath.Join(t.TempDir(), "test.db"),
Server: &configServer{},
DefaultBlog: "en",
Blogs: map[string]*configBlog{
"en": {
Lang: "en",
Blogroll: &configBlogroll{
Enabled: true,
Path: "/br",
AuthHeader: "Authheader",
AuthValue: "Authtoken",
Opml: "",
Categories: []string{"A", "B"},
User: &configUser{},
Cache: &configCache{
Enable: false,
_ = app.initDatabase(false)
defer app.db.close()
fc.setFakeResponse(http.StatusOK, `
<opml version="2.0">
<dateCreated>Tue, 30 Nov 2021 19:34:38 UTC</dateCreated>
<outline text="B">
<outline text="A text" xmlUrl="" htmlUrl="" title="A title"/>
<outline text="B text" xmlUrl="" htmlUrl="" title="B title"/>
<outline text="A">
<outline text="C text" xmlUrl="" htmlUrl="" title="C title"/>
<outline text="D text" xmlUrl="" htmlUrl="" title="D title"/>
<outline text="C">
// Test getting the blogroll
// Tests sorting and filtering
outlines, err := app.getBlogrollOutlines("en")
require.NoError(t, err)
require.NotNil(t, outlines)
if assert.Len(t, outlines, 2) {
assert.Equal(t, "A", outlines[0].Text)
assert.Equal(t, "B", outlines[1].Text)
if assert.Len(t, outlines[0].Outlines, 2) {
assert.Equal(t, "C text", outlines[0].Outlines[0].Text)
assert.Equal(t, "C title", outlines[0].Outlines[0].Title)
// Test getting the OPML
rec := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/br.opml", nil)
req = req.WithContext(context.WithValue(req.Context(), blogKey, "en"))
app.serveBlogrollExport(rec, req)
assert.Equal(t, 200, rec.Code)