intake/core/db_test.go

49 lines
961 B
Go
Raw Normal View History

package core
import (
"testing"
_ "github.com/mattn/go-sqlite3"
)
func TestDeleteSourceCascade(t *testing.T) {
db := EphemeralDb(t)
if err := AddSource(db, "source1"); err != nil {
t.Fatal(err)
}
if err := AddSource(db, "source2"); err != nil {
t.Fatal(err)
}
if err := AddItem(db, "source1", "item1", "", "", "", "", 0); err != nil {
t.Fatal(err)
}
if err := AddItem(db, "source2", "item2", "", "", "", "", 0); err != nil {
t.Fatal(err)
}
items, err := GetAllActiveItems(db)
if err != nil {
t.Fatal(err)
}
if len(items) != 2 {
t.Fatal("Expected 2 items")
}
if err := DeleteSource(db, "source1"); err != nil {
t.Fatal(err)
}
items, err = GetAllActiveItems(db)
if err != nil {
t.Fatal(err)
}
if len(items) != 1 {
t.Fatal("Expected only 1 item after source delete")
}
err = AddItem(db, "source1", "item3", "", "", "", "", 0)
if err == nil {
t.Fatal("Unexpected success adding item for nonexistent source")
}
}