planner/plan/command/list_test.go

58 lines
1.0 KiB
Go
Raw Normal View History

2024-10-29 07:22:04 +01:00
package command_test
import (
"testing"
"go-mod.ewintr.nl/planner/item"
"go-mod.ewintr.nl/planner/plan/command"
"go-mod.ewintr.nl/planner/plan/storage/memory"
)
func TestList(t *testing.T) {
t.Parallel()
2024-12-24 08:00:23 +01:00
taskRepo := memory.NewTask()
2024-10-29 07:22:04 +01:00
localRepo := memory.NewLocalID()
2024-12-24 08:00:23 +01:00
e := item.Task{
2024-12-19 12:06:03 +01:00
ID: "id",
Date: item.NewDate(2024, 10, 7),
2024-12-24 08:00:23 +01:00
TaskBody: item.TaskBody{
2024-10-29 07:22:04 +01:00
Title: "name",
},
}
2024-12-24 08:00:23 +01:00
if err := taskRepo.Store(e); err != nil {
2024-10-29 07:22:04 +01:00
t.Errorf("exp nil, got %v", err)
}
if err := localRepo.Store(e.ID, 1); err != nil {
t.Errorf("exp nil, got %v", err)
}
for _, tc := range []struct {
name string
main []string
expErr bool
}{
{
name: "empty",
main: []string{},
},
{
name: "list",
main: []string{"list"},
},
{
name: "wrong",
main: []string{"delete"},
expErr: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
2024-12-24 08:00:23 +01:00
cmd := command.NewList(localRepo, taskRepo)
2024-10-29 07:22:04 +01:00
actErr := cmd.Execute(tc.main, nil) != nil
if tc.expErr != actErr {
t.Errorf("exp %v, got %v", tc.expErr, actErr)
}
})
}
}