test for mem
This commit is contained in:
parent
a1ee001bba
commit
b667cb1616
|
@ -25,10 +25,10 @@ func NewTask(description string) Task {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) ID() string {
|
func (t Task) ID() string {
|
||||||
return t.id
|
return t.id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) Updated() time.Time {
|
func (t Task) Updated() time.Time {
|
||||||
return t.updated
|
return t.updated
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,69 +2,87 @@ package storage_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"code.ewintr.nl/planner/service"
|
"code.ewintr.nl/planner/planner"
|
||||||
"github.com/google/go-cmp/cmp"
|
"code.ewintr.nl/planner/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMemoryProjects(t *testing.T) {
|
func TestMemoryItem(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
mem := service.NewMemory()
|
mem := storage.NewMemory()
|
||||||
|
|
||||||
t.Log("start empty")
|
t.Log("start empty")
|
||||||
actProjects, actErr := mem.FindAllProjects()
|
actItems, actErr := mem.NewSince(time.Time{})
|
||||||
if actErr != nil {
|
if actErr != nil {
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
if len(actProjects) != 0 {
|
if len(actItems) != 0 {
|
||||||
t.Errorf("exp 0, got %d", len(actProjects))
|
t.Errorf("exp 0, got %d", len(actItems))
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log("add one")
|
t.Log("add one")
|
||||||
p1 := service.Project{
|
t1 := planner.NewTask("test")
|
||||||
ID: "p1",
|
if actErr := mem.Store(t1); actErr != nil {
|
||||||
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)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
actProjects, actErr = mem.FindAllProjects()
|
actItems, actErr = mem.NewSince(time.Time{})
|
||||||
if actErr != nil {
|
if actErr != nil {
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
expProjects := []service.Project{p1}
|
if len(actItems) != 1 {
|
||||||
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
t.Errorf("exp 1, gor %d", len(actItems))
|
||||||
t.Errorf("(-exp, +got):\n%s", diff)
|
|
||||||
}
|
}
|
||||||
|
if actItems[0].ID() != t1.ID() {
|
||||||
|
t.Errorf("exp %v, got %v", actItems[0].ID(), t1.ID())
|
||||||
|
}
|
||||||
|
|
||||||
|
before := time.Now()
|
||||||
|
|
||||||
t.Log("add second")
|
t.Log("add second")
|
||||||
if actErr := mem.StoreProject(p2); actErr != nil {
|
t2 := planner.NewTask("test 2")
|
||||||
|
if actErr := mem.Store(t2); actErr != nil {
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
actProjects, actErr = mem.FindAllProjects()
|
actItems, actErr = mem.NewSince(time.Time{})
|
||||||
if actErr != nil {
|
if actErr != nil {
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
expProjects = []service.Project{p1, p2}
|
if len(actItems) != 2 {
|
||||||
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
t.Errorf("exp 2, gor %d", len(actItems))
|
||||||
t.Errorf("(-exp, +act):\n%s", diff)
|
}
|
||||||
|
if actItems[0].ID() != t1.ID() {
|
||||||
|
t.Errorf("exp %v, got %v", actItems[0].ID(), t1.ID())
|
||||||
|
}
|
||||||
|
if actItems[1].ID() != t2.ID() {
|
||||||
|
t.Errorf("exp %v, got %v", actItems[1].ID(), t2.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Log("remove first")
|
actItems, actErr = mem.NewSince(before)
|
||||||
if actErr := mem.RemoveProject(p1.ID); actErr != nil {
|
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
|
||||||
}
|
|
||||||
actProjects, actErr = mem.FindAllProjects()
|
|
||||||
if actErr != nil {
|
if actErr != nil {
|
||||||
t.Errorf("exp nil, got %v", actErr)
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
}
|
}
|
||||||
expProjects = []service.Project{p2}
|
if len(actItems) != 1 {
|
||||||
if diff := cmp.Diff(expProjects, actProjects); diff != "" {
|
t.Errorf("exp 1, gor %d", len(actItems))
|
||||||
t.Errorf("-exp, +act:\b%s", diff)
|
|
||||||
}
|
}
|
||||||
|
if actItems[0].ID() != t2.ID() {
|
||||||
|
t.Errorf("exp %v, got %v", actItems[0].ID(), t2.ID())
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
t.Log("remove first")
|
||||||
|
if actErr := mem.RemoveProject(p1.ID); actErr != nil {
|
||||||
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
|
}
|
||||||
|
actItems , actErr = mem.FindAllItems ()
|
||||||
|
if actErr != nil {
|
||||||
|
t.Errorf("exp nil, got %v", actErr)
|
||||||
|
}
|
||||||
|
expItems = []service.Project{p2}
|
||||||
|
if diff := cmp.Diff(expItems
|
||||||
|
, actItems ); diff != "" {
|
||||||
|
t.Errorf("-exp, +act:\b%s", diff)
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue