start storage tests

This commit is contained in:
Nazar Kanaev
2021-04-05 19:02:31 +01:00
parent 2e5ccc3158
commit 09bfc47ef0
3 changed files with 85 additions and 20 deletions

41
src/storage/feed_test.go Normal file
View File

@@ -0,0 +1,41 @@
package storage
import (
"reflect"
"testing"
)
func TestCreateFeed(t *testing.T) {
db := testDB()
feed1 := db.CreateFeed("title", "", "http://example.com", "http://example.com/feed.xml", nil)
if feed1 == nil || feed1.Id == 0 {
t.Fatal("expected feed")
}
feed2 := db.GetFeed(feed1.Id)
if feed2 == nil || !reflect.DeepEqual(feed1, feed2) {
t.Fatal("invalid feed")
}
}
func TestReadFeed(t *testing.T) {
db := testDB()
if db.GetFeed(100500) != nil {
t.Fatal("cannot get nonexistent feed")
}
}
func TestDeleteFeed(t *testing.T) {
db := testDB()
feed1 := db.CreateFeed("title", "", "http://example.com", "http://example.com/feed.xml", nil)
if db.DeleteFeed(100500) {
t.Error("cannot delete what does not exist")
}
if !db.DeleteFeed(feed1.Id) {
t.Fatal("did not delete existing feed")
}
if db.GetFeed(feed1.Id) != nil {
t.Fatal("feed still exists")
}
}