package command_test import ( "testing" "time" "github.com/google/go-cmp/cmp" "go-mod.ewintr.nl/planner/item" "go-mod.ewintr.nl/planner/plan/command" "go-mod.ewintr.nl/planner/plan/storage/memory" "go-mod.ewintr.nl/planner/sync/client" ) func TestSync(t *testing.T) { t.Parallel() syncClient := client.NewMemory() syncRepo := memory.NewSync() localIDRepo := memory.NewLocalID() eventRepo := memory.NewEvent() // now := time.Now() it := item.Item{ ID: "a", Kind: item.KindEvent, Body: `{ "title":"title", "start":"2024-10-18T08:00:00Z", "duration":"1h" }`, } syncClient.Update([]item.Item{it}) for _, tc := range []struct { name string ks []item.Kind ts time.Time expItems []item.Item }{ { name: "single", ks: []item.Kind{item.KindEvent}, expItems: []item.Item{it}, }, } { t.Run(tc.name, func(t *testing.T) { if err := command.Sync(syncClient, syncRepo, localIDRepo, eventRepo, false); err != nil { t.Errorf("exp nil, got %v", err) } actItems, actErr := syncClient.Updated(tc.ks, tc.ts) if actErr != nil { t.Errorf("exp nil, got %v", actErr) } if diff := cmp.Diff(tc.expItems, actItems); diff != "" { t.Errorf("(exp +, got -)\n%s", diff) } }) } }