gte/internal/process/sync_test.go

48 lines
1.3 KiB
Go
Raw Normal View History

2021-06-25 09:14:27 +02:00
package process_test
import (
"testing"
"git.ewintr.nl/go-kit/test"
"git.ewintr.nl/gte/internal/process"
"git.ewintr.nl/gte/internal/storage"
"git.ewintr.nl/gte/internal/task"
"git.ewintr.nl/gte/pkg/mstore"
)
func TestSyncProcess(t *testing.T) {
task1 := &task.Task{
Id: "id1",
Version: 1,
Action: "action1",
Folder: task.FOLDER_NEW,
}
task2 := &task.Task{
Id: "id2",
Version: 1,
Action: "action2",
Folder: task.FOLDER_UNPLANNED,
}
2021-08-20 09:30:49 +02:00
localTask1 := &task.LocalTask{Task: *task1, LocalId: 1}
localTask2 := &task.LocalTask{Task: *task2, LocalId: 2}
2021-08-20 09:06:35 +02:00
2021-06-25 09:14:27 +02:00
mstorer, err := mstore.NewMemory(task.KnownFolders)
test.OK(t, err)
test.OK(t, mstorer.Add(task1.Folder, task1.FormatSubject(), task1.FormatBody()))
test.OK(t, mstorer.Add(task2.Folder, task2.FormatSubject(), task2.FormatBody()))
remote := storage.NewRemoteRepository(mstorer)
local := storage.NewMemory()
syncer := process.NewSync(remote, local)
actResult, err := syncer.Process()
test.OK(t, err)
test.Equals(t, 2, actResult.Count)
actTasks1, err := local.FindAllInFolder(task.FOLDER_NEW)
test.OK(t, err)
2021-08-20 09:06:35 +02:00
test.Equals(t, []*task.LocalTask{localTask1}, actTasks1)
2021-06-25 09:14:27 +02:00
actTasks2, err := local.FindAllInFolder(task.FOLDER_UNPLANNED)
test.OK(t, err)
2021-08-20 09:06:35 +02:00
test.Equals(t, []*task.LocalTask{localTask2}, actTasks2)
2021-06-25 09:14:27 +02:00
}