planner/plan/storage/memory/sync_test.go

60 lines
1.0 KiB
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"
2024-10-16 07:34:08 +02:00
"time"
2024-10-09 07:15:17 +02:00
"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-16 07:34:08 +02:00
now := time.Now()
ts := now
2024-10-09 07:15:17 +02:00
count := 3
for i := 0; i < count; i++ {
mem.Store(item.Item{
2024-10-16 07:34:08 +02:00
ID: fmt.Sprintf("id-%d", i),
Updated: ts,
2024-10-09 07:15:17 +02:00
})
2024-10-16 07:34:08 +02:00
ts = ts.Add(-1 * time.Minute)
2024-10-09 07:15:17 +02:00
}
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
2024-10-16 07:34:08 +02:00
t.Log("last update")
actLU, actErr := mem.LastUpdate()
if actErr != nil {
t.Errorf("exp nil, got %v", actErr)
}
if !actLU.Equal(now) {
t.Errorf("exp %v, got %v", now, actLU)
}
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
}