aboutsummaryrefslogtreecommitdiffstats
path: root/models/feed
diff options
context:
space:
mode:
Diffstat (limited to 'models/feed')
-rw-r--r--models/feed/feed.go9
-rw-r--r--models/feed/feed_test.go35
2 files changed, 39 insertions, 5 deletions
diff --git a/models/feed/feed.go b/models/feed/feed.go
index e2730c7..b0f7c69 100644
--- a/models/feed/feed.go
+++ b/models/feed/feed.go
@@ -1,10 +1,11 @@
package feed
import (
- "adammathes.com/neko/models"
- "github.com/PuerkitoBio/goquery"
"log"
"net/http"
+
+ "adammathes.com/neko/models"
+ "github.com/PuerkitoBio/goquery"
)
type Feed struct {
@@ -103,8 +104,8 @@ func (f *Feed) ByUrl(url string) error {
}
func (f *Feed) Create() error {
- res, err := models.DB.Exec(`INSERT INTO feed(url, title)
- VALUES(?, ?)`, f.Url, f.Title)
+ res, err := models.DB.Exec(`INSERT INTO feed(url, title, category)
+ VALUES(?, ?, ?)`, f.Url, f.Title, f.Category)
if err != nil {
return err
}
diff --git a/models/feed/feed_test.go b/models/feed/feed_test.go
index d02916a..715a705 100644
--- a/models/feed/feed_test.go
+++ b/models/feed/feed_test.go
@@ -3,6 +3,7 @@ package feed
import (
"net/http"
"net/http/httptest"
+ "path/filepath"
"testing"
"adammathes.com/neko/config"
@@ -11,7 +12,7 @@ import (
func setupTestDB(t *testing.T) {
t.Helper()
- config.Config.DBFile = ":memory:"
+ config.Config.DBFile = filepath.Join(t.TempDir(), "test.db")
models.InitDB()
t.Cleanup(func() {
if models.DB != nil {
@@ -409,3 +410,35 @@ func TestCategoriesEmpty(t *testing.T) {
t.Errorf("Should have 0 categories on empty DB, got %d", len(cats))
}
}
+
+func TestResolveFeedURLRelativePaths(t *testing.T) {
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ w.WriteHeader(200)
+ w.Write([]byte(`<html><head><link rel="alternate" type="application/rss+xml" href="/rss.xml"/></head></html>`))
+ }))
+ defer ts.Close()
+
+ result := ResolveFeedURL(ts.URL)
+ if result != ts.URL+"/rss.xml" {
+ t.Errorf("Expected joined relative URL, got %q", result)
+ }
+}
+
+func TestResolveFeedURLMultipleLinks(t *testing.T) {
+ ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "text/html")
+ w.WriteHeader(200)
+ w.Write([]byte(`<html><head>
+ <link rel="alternate" type="application/atom+xml" href="http://example.com/atom.xml"/>
+ <link rel="alternate" type="application/rss+xml" href="http://example.com/rss.xml"/>
+ </head></html>`))
+ }))
+ defer ts.Close()
+
+ result := ResolveFeedURL(ts.URL)
+ // it should pick the first matched one or whichever type is handled first in the code
+ if result != "http://example.com/atom.xml" && result != "http://example.com/rss.xml" {
+ t.Errorf("Expected one of the discovered feed URLs, got %q", result)
+ }
+}