From e9e9598c8c9e7404e1878fcc61fd5656d6676a02 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Wed, 20 Nov 2024 07:31:20 +0100 Subject: [PATCH] flag tests --- plan/command/flag_test.go | 85 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/plan/command/flag_test.go b/plan/command/flag_test.go index af03dd8..a663d2c 100644 --- a/plan/command/flag_test.go +++ b/plan/command/flag_test.go @@ -2,6 +2,7 @@ package command_test import ( "testing" + "time" "go-mod.ewintr.nl/planner/plan/command" ) @@ -12,7 +13,7 @@ func TestFlagString(t *testing.T) { valid := "test" f := command.FlagString{} if f.IsSet() { - t.Errorf("exp false, gor true") + t.Errorf("exp false, got true") } if err := f.Set(valid); err != nil { @@ -30,5 +31,85 @@ func TestFlagString(t *testing.T) { if act != valid { 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) + } }