planner/plan/command/flag_test.go

116 lines
1.9 KiB
Go
Raw Normal View History

2024-11-13 07:24:21 +01:00
package command_test
import (
"testing"
2024-11-20 07:31:20 +01:00
"time"
2024-11-13 07:24:21 +01:00
"go-mod.ewintr.nl/planner/plan/command"
)
func TestFlagString(t *testing.T) {
t.Parallel()
valid := "test"
f := command.FlagString{}
if f.IsSet() {
2024-11-20 07:31:20 +01:00
t.Errorf("exp false, got true")
2024-11-13 07:24:21 +01:00
}
if err := f.Set(valid); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(string)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
2024-11-20 07:31:20 +01:00
}
func TestFlagDate(t *testing.T) {
t.Parallel()
valid := time.Date(2024, 11, 20, 0, 0, 0, 0, time.UTC)
validStr := "2024-11-20"
f := command.FlagDate{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(validStr); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(time.Time)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
}
func TestFlagTime(t *testing.T) {
t.Parallel()
2024-11-13 07:24:21 +01:00
2024-11-20 07:31:20 +01:00
valid := time.Date(0, 1, 1, 12, 30, 0, 0, time.UTC)
validStr := "12:30"
f := command.FlagTime{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(validStr); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(time.Time)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
}
func TestFlagDurationTime(t *testing.T) {
t.Parallel()
valid := time.Hour
validStr := "1h"
f := command.FlagDuration{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(validStr); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(time.Duration)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
2024-11-13 07:24:21 +01:00
}