2024-10-03 07:32:48 +02:00
|
|
|
package memory
|
2024-09-23 07:48:18 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"go-mod.ewintr.nl/planner/item"
|
2024-12-29 09:32:49 +01:00
|
|
|
"go-mod.ewintr.nl/planner/plan/storage"
|
2024-09-23 07:48:18 +02:00
|
|
|
)
|
|
|
|
|
2024-12-24 08:00:23 +01:00
|
|
|
func TestTask(t *testing.T) {
|
2024-09-23 07:48:18 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
2024-12-24 08:00:23 +01:00
|
|
|
mem := NewTask()
|
2024-09-23 07:48:18 +02:00
|
|
|
|
|
|
|
t.Log("empty")
|
2024-12-29 09:32:49 +01:00
|
|
|
actTasks, actErr := mem.FindMany(storage.TaskListParams{})
|
2024-09-23 07:48:18 +02:00
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if len(actTasks) != 0 {
|
|
|
|
t.Errorf("exp 0, got %d", len(actTasks))
|
2024-09-23 07:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("store")
|
2024-12-24 08:00:23 +01:00
|
|
|
tsk1 := item.Task{
|
2024-12-29 09:32:49 +01:00
|
|
|
ID: "id-1",
|
|
|
|
Date: item.NewDate(2024, 12, 29),
|
2024-09-23 07:48:18 +02:00
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if err := mem.Store(tsk1); err != nil {
|
2024-09-23 07:48:18 +02:00
|
|
|
t.Errorf("exp nil, got %v", err)
|
|
|
|
}
|
|
|
|
|
2024-12-24 08:00:23 +01:00
|
|
|
tsk2 := item.Task{
|
2024-09-23 07:48:18 +02:00
|
|
|
ID: "id-2",
|
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if err := mem.Store(tsk2); err != nil {
|
2024-09-23 07:48:18 +02:00
|
|
|
t.Errorf("exp nil, got %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("find one")
|
2024-12-29 09:32:49 +01:00
|
|
|
actTask, actErr := mem.FindOne(tsk1.ID)
|
2024-09-23 07:48:18 +02:00
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if actTask.ID != tsk1.ID {
|
|
|
|
t.Errorf("exp %v, got %v", tsk1.ID, actTask.ID)
|
2024-09-23 07:48:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("find all")
|
2024-12-29 09:32:49 +01:00
|
|
|
actTasks, actErr = mem.FindMany(storage.TaskListParams{})
|
2024-09-23 07:48:18 +02:00
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
2024-12-24 08:00:23 +01:00
|
|
|
if diff := item.TaskDiffs([]item.Task{tsk1, tsk2}, actTasks); diff != "" {
|
2024-09-23 07:48:18 +02:00
|
|
|
t.Errorf("(exp -, got +)\n%s", diff)
|
|
|
|
}
|
2024-12-29 09:32:49 +01:00
|
|
|
|
|
|
|
t.Log("fond some")
|
|
|
|
actTasks, actErr = mem.FindMany(storage.TaskListParams{
|
|
|
|
Date: item.NewDate(2024, 12, 29),
|
|
|
|
})
|
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
if diff := item.TaskDiffs([]item.Task{tsk1}, actTasks); diff != "" {
|
|
|
|
t.Errorf("(exp -, got +)\n%s", diff)
|
|
|
|
}
|
|
|
|
|
2024-09-23 07:48:18 +02:00
|
|
|
}
|