Rssmon2/rss/item_test.go

62 lines
974 B
Go

package rss
import (
"testing"
"github.com/mmcdole/gofeed"
)
func Test_RSSItem(t *testing.T) {
cases := []struct {
input gofeed.Item
filter string
output Item
}{
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: "",
},
filter: "",
output: Item{
Name: "a",
Link: "b",
Content: "",
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: `x y <img src="asdf"></img>`,
},
filter: "[a-z]*",
output: Item{
Name: "a",
Link: "b",
Content: "x\n<br>\ny",
},
},
{
input: gofeed.Item{
Title: "a",
Link: "b",
Content: "x y",
},
filter: "[a-z]*",
output: Item{
Name: "a",
Link: "b",
Content: "x\n<br>\ny",
},
},
}
for _, c := range cases {
output := fromGofeedItem(&c.input, c.filter)
if *output != c.output {
t.Errorf("failed to convert gofeed: wanted %v, got %v", c.output, *output)
}
}
}