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.
 
 
 
 

40 lines
782 B

package main
import (
"io/ioutil"
"os"
"path"
"testing"
)
const (
url = "https://example.com/"
)
func TestEnqueue(t *testing.T) {
testDir, err := ioutil.TempDir("", "feed-test")
if err != nil {
t.Fatalf("Can't create temp dir: %v", err)
}
dbPath := path.Join(testDir, "test.db")
defer os.RemoveAll(testDir)
feed, err := newFeed(dbPath, &dummyContentFetcher{})
if err != nil {
t.Fatalf("Can't open the feed: %v", err)
}
defer feed.close()
items := feed.items()
if len(items) != 0 {
t.Fatalf("There are published items in the feed: %v", items)
}
feed.add(url)
feed.publish()
items = feed.items()
if len(items) != 1 {
t.Errorf("There are unexpected number of items: %v", items)
}
if items[0].URL != url {
t.Errorf("Unexpected url: %v", items)
}
}