2024-08-20 08:34:11 +02:00
|
|
|
package storage_test
|
2024-08-16 14:25:06 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.ewintr.nl/planner/service"
|
2024-08-18 19:34:27 +02:00
|
|
|
"github.com/google/go-cmp/cmp"
|
2024-08-16 14:25:06 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestMemoryProjects(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
mem := service.NewMemory()
|
2024-08-18 19:34:27 +02:00
|
|
|
|
|
|
|
t.Log("start empty")
|
2024-08-16 14:25:06 +02:00
|
|
|
actProjects, actErr := mem.FindAllProjects()
|
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
if len(actProjects) != 0 {
|
|
|
|
t.Errorf("exp 0, got %d", len(actProjects))
|
|
|
|
}
|
2024-08-18 19:34:27 +02:00
|
|
|
|
|
|
|
t.Log("add one")
|
|
|
|
p1 := service.Project{
|
|
|
|
ID: "p1",
|
|
|
|
Name: "project 1",
|
|
|
|
}
|
|
|
|
p2 := service.Project{
|
|
|
|
ID: "p2",
|
|
|
|
Name: "project 2",
|
|
|
|
}
|
|
|
|
if actErr := mem.StoreProject(p1); actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
actProjects, actErr = mem.FindAllProjects()
|
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
expProjects := []service.Project{p1}
|
|
|
|
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
|
|
|
t.Errorf("(-exp, +got):\n%s", diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("add second")
|
|
|
|
if actErr := mem.StoreProject(p2); actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
actProjects, actErr = mem.FindAllProjects()
|
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
expProjects = []service.Project{p1, p2}
|
|
|
|
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
|
|
|
t.Errorf("(-exp, +act):\n%s", diff)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Log("remove first")
|
|
|
|
if actErr := mem.RemoveProject(p1.ID); actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
actProjects, actErr = mem.FindAllProjects()
|
|
|
|
if actErr != nil {
|
|
|
|
t.Errorf("exp nil, got %v", actErr)
|
|
|
|
}
|
|
|
|
expProjects = []service.Project{p2}
|
|
|
|
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
|
|
|
t.Errorf("-exp, +act:\b%s", diff)
|
|
|
|
}
|
2024-08-16 14:25:06 +02:00
|
|
|
}
|