planner/plan/command/show_test.go

86 lines
1.7 KiB
Go
Raw Normal View History

2024-12-29 09:32:49 +01:00
package command_test
import (
"fmt"
"testing"
"go-mod.ewintr.nl/planner/item"
"go-mod.ewintr.nl/planner/plan/command"
"go-mod.ewintr.nl/planner/plan/storage/memory"
)
func TestShow(t *testing.T) {
t.Parallel()
2025-01-13 09:13:48 +01:00
mems := memory.New()
2024-12-29 09:32:49 +01:00
tsk := item.Task{
ID: "id",
Date: item.NewDate(2024, 10, 7),
TaskBody: item.TaskBody{
Title: "name",
},
}
2025-01-13 09:13:48 +01:00
if err := mems.Task(nil).Store(tsk); err != nil {
2024-12-29 09:32:49 +01:00
t.Errorf("exp nil, got %v", err)
}
2025-01-13 09:13:48 +01:00
if err := mems.LocalID(nil).Store(tsk.ID, 1); err != nil {
2024-12-29 09:32:49 +01:00
t.Errorf("exp nil, got %v", err)
}
for _, tc := range []struct {
name string
main []string
expData [][]string
expParseErr bool
expDoErr bool
}{
{
name: "empty",
main: []string{},
expParseErr: true,
},
{
name: "wrong",
main: []string{"delete"},
expParseErr: true,
},
{
name: "local id",
main: []string{"1"},
expData: [][]string{
{"title", tsk.Title},
{"local id", fmt.Sprintf("%d", 1)},
{"date", tsk.Date.String()},
{"time", tsk.Time.String()},
{"duration", tsk.Duration.String()},
{"recur", ""},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
// parse
cmd, actParseErr := command.NewShowArgs().Parse(tc.main, nil)
if tc.expParseErr != (actParseErr != nil) {
t.Errorf("exp %v, got %v", tc.expParseErr, actParseErr != nil)
}
if tc.expParseErr {
return
}
// do
2025-01-13 09:13:48 +01:00
_, actDoErr := cmd.Do(mems, nil)
2024-12-29 09:32:49 +01:00
if tc.expDoErr != (actDoErr != nil) {
t.Errorf("exp %v, got %v", tc.expDoErr, actDoErr != nil)
}
if tc.expDoErr {
return
}
// if diff := cmp.Diff(tc.expData, actData); diff != "" {
// t.Errorf("(+exp, -got)%s\n", diff)
// }
})
}
}