encodable a good
Former-commit-id: a0afebd82dfd256ec70c02c607af2a9b3b4b046f
This commit is contained in:
44
rss/feed_test.go
Normal file
44
rss/feed_test.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package rss
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"local/rssmon3/config"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func initRSSFeed() {
|
||||
os.Args = []string{"a", "-db", "map"}
|
||||
if err := config.New(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRSSFeedEncodeDecode(t *testing.T) {
|
||||
initRSSFeed()
|
||||
|
||||
f := newFeed("key")
|
||||
f.Updated = time.Now()
|
||||
f.TitleFilter = "a"
|
||||
f.ContentFilter = "b"
|
||||
f.Tags = []string{"c"}
|
||||
|
||||
b, err := f.Encode()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
g := newFeed("key")
|
||||
if err := g.Decode(b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fb, _ := json.Marshal(f)
|
||||
gb, _ := json.Marshal(f)
|
||||
if string(fb) != string(gb) {
|
||||
t.Errorf("%v => %v", *f, *g)
|
||||
}
|
||||
|
||||
t.Logf("%s vs. %s", fb, gb)
|
||||
}
|
||||
Reference in New Issue
Block a user