planner/plan/storage/memory/event_test.go

56 lines
1001 B
Go
Raw Normal View History

2024-10-03 07:32:48 +02:00
package memory
2024-09-23 07:48:18 +02:00
import (
"testing"
"go-mod.ewintr.nl/planner/item"
)
2024-10-03 07:32:48 +02:00
func TestEvent(t *testing.T) {
2024-09-23 07:48:18 +02:00
t.Parallel()
2024-10-03 07:32:48 +02:00
mem := NewEvent()
2024-09-23 07:48:18 +02:00
t.Log("empty")
actEvents, actErr := mem.FindAll()
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
if len(actEvents) != 0 {
t.Errorf("exp 0, got %d", len(actEvents))
}
t.Log("store")
e1 := item.Event{
ID: "id-1",
}
if err := mem.Store(e1); err != nil {
t.Errorf("exp nil, got %v", err)
}
e2 := item.Event{
ID: "id-2",
}
if err := mem.Store(e2); err != nil {
t.Errorf("exp nil, got %v", err)
}
t.Log("find one")
actEvent, actErr := mem.Find(e1.ID)
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
if actEvent.ID != e1.ID {
t.Errorf("exp %v, got %v", e1.ID, actEvent.ID)
}
t.Log("find all")
actEvents, actErr = mem.FindAll()
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
2024-12-19 12:06:03 +01:00
if diff := item.EventDiffs([]item.Event{e1, e2}, actEvents); diff != "" {
2024-09-23 07:48:18 +02:00
t.Errorf("(exp -, got +)\n%s", diff)
}
}