flag tests

This commit is contained in:
Erik Winter 2024-11-20 07:31:20 +01:00
parent 6ead021edb
commit e9e9598c8c
1 changed files with 83 additions and 2 deletions

View File

@ -2,6 +2,7 @@ package command_test
import ( import (
"testing" "testing"
"time"
"go-mod.ewintr.nl/planner/plan/command" "go-mod.ewintr.nl/planner/plan/command"
) )
@ -12,7 +13,7 @@ func TestFlagString(t *testing.T) {
valid := "test" valid := "test"
f := command.FlagString{} f := command.FlagString{}
if f.IsSet() { if f.IsSet() {
t.Errorf("exp false, gor true") t.Errorf("exp false, got true")
} }
if err := f.Set(valid); err != nil { if err := f.Set(valid); err != nil {
@ -30,5 +31,85 @@ func TestFlagString(t *testing.T) {
if act != valid { if act != valid {
t.Errorf("exp %v, got %v", valid, act) t.Errorf("exp %v, got %v", valid, act)
} }
}
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()
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)
}
} }