Compare commits

...

2 Commits

Author SHA1 Message Date
Erik Winter 6fe7fe009e wip 2024-10-09 07:26:39 +02:00
Erik Winter 5ab5505d2b mem test 2024-10-09 07:15:17 +02:00
3 changed files with 59 additions and 6 deletions

View File

@ -8,7 +8,7 @@ import (
var SyncCmd = &cli.Command{ var SyncCmd = &cli.Command{
Name: "sync", Name: "sync",
Usage: "Synchonize with server", Usage: "Synchronize with server",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "full", Name: "full",
@ -26,6 +26,10 @@ func NewSyncCmd(client *client.Client, localRepo storage.LocalID, eventRepo stor
} }
func Sync(client *client.Client, localRepo storage.LocalID, eventRepo storage.Event, full bool) error { func Sync(client *client.Client, localRepo storage.LocalID, eventRepo storage.Event, full bool) error {
// find local new and updated
// send new and updated
//
// get new/updated items // get new/updated items
// delete deleted // delete deleted
@ -34,9 +38,5 @@ func Sync(client *client.Client, localRepo storage.LocalID, eventRepo storage.Ev
// localid and add new // localid and add new
// find local new and updated
// send new and updated
return nil return nil
} }

View File

@ -1,14 +1,45 @@
package memory_test package memory_test
import "testing" import (
"fmt"
"testing"
"go-mod.ewintr.nl/planner/item"
"go-mod.ewintr.nl/planner/plan/storage/memory"
)
func TestSync(t *testing.T) { func TestSync(t *testing.T) {
t.Parallel() t.Parallel()
mem := memory.NewSync()
t.Log("store") t.Log("store")
count := 3
for i := 0; i < count; i++ {
mem.Store(item.Item{
ID: fmt.Sprintf("id-%d", i),
})
}
t.Log("find all") t.Log("find all")
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))
}
t.Log("delete all") t.Log("delete all")
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))
}
} }

22
sync/client/memory.go Normal file
View File

@ -0,0 +1,22 @@
package client
import (
"time"
"go-mod.ewintr.nl/planner/item"
)
type Memory struct {
}
func NewMemory() *Memory {
return &Memory{}
}
func (m *Memory) Update(items []item.Item) error {
return nil
}
func (m *Memory) Updated(kw []item.Kind, ts time.Time) ([]item.Item, error) {
return nil, nil
}