planner/plan/storage/memory/sync_test.go

46 lines
794 B
Go
Raw Normal View History

2024-10-08 07:21:27 +02:00
package memory_test
2024-10-09 07:15:17 +02:00
import (
"fmt"
"testing"
"go-mod.ewintr.nl/planner/item"
"go-mod.ewintr.nl/planner/plan/storage/memory"
)
2024-10-08 07:21:27 +02:00
func TestSync(t *testing.T) {
t.Parallel()
2024-10-08 07:22:06 +02:00
2024-10-09 07:15:17 +02:00
mem := memory.NewSync()
2024-10-08 07:22:06 +02:00
t.Log("store")
2024-10-09 07:15:17 +02:00
count := 3
for i := 0; i < count; i++ {
mem.Store(item.Item{
ID: fmt.Sprintf("id-%d", i),
})
}
2024-10-08 07:22:06 +02:00
t.Log("find all")
2024-10-09 07:15:17 +02:00
actItems, actErr := mem.FindAll()
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
if len(actItems) != count {
t.Errorf("exp %v, got %v", count, len(actItems))
}
2024-10-08 07:22:06 +02:00
t.Log("delete all")
2024-10-09 07:15:17 +02:00
if err := mem.DeleteAll(); err != nil {
t.Errorf("exp nil, got %v", err)
}
actItems, actErr = mem.FindAll()
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
if len(actItems) != 0 {
t.Errorf("exp 0, got %v", len(actItems))
}
2024-10-08 07:22:06 +02:00
2024-10-08 07:21:27 +02:00
}