46 lines
997 B
Go
46 lines
997 B
Go
package core
|
|
|
|
import "testing"
|
|
|
|
func TestItemFormatsExist(t *testing.T) {
|
|
for name := range AvailableFormats {
|
|
formatter, err := FormatAs(name)
|
|
if err != nil {
|
|
t.Fatalf("error getting formatter for available format %s: %v", name, err)
|
|
}
|
|
if formatter == nil {
|
|
t.Fatalf("formatter %s is nil", name)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestItemRoundTrip(t *testing.T) {
|
|
db := EphemeralDb(t)
|
|
if err := AddSource(db, "_"); err != nil {
|
|
t.Fatalf("failed to create source: %v", err)
|
|
}
|
|
|
|
item1 := Item{
|
|
Source: "_",
|
|
Id: "a",
|
|
Created: 0,
|
|
Active: true,
|
|
Title: "title",
|
|
Author: "author",
|
|
Body: "body",
|
|
Link: "link",
|
|
Time: 123456,
|
|
}
|
|
if err := AddItems(db, []Item{item1}); err != nil {
|
|
t.Fatalf("update failed: %v", err)
|
|
}
|
|
item2, err := GetItem(db, item1.Source, item1.Id)
|
|
if err != nil {
|
|
t.Fatalf("could not get item: %v", err)
|
|
}
|
|
item2.Created = 0 // automatically set by db
|
|
if !ItemsAreEqual(item1, item2) {
|
|
t.Fatalf("items are not equal, err %v", err)
|
|
}
|
|
}
|