From 9c9d13eb09cdcf4c8b9e934a4816ab6105852124 Mon Sep 17 00:00:00 2001 From: horockey Date: Wed, 7 Aug 2024 17:59:47 +0300 Subject: [PATCH] test: fix tests to cover empty layout scenario --- flag_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/flag_test.go b/flag_test.go index bc0c377373..91b16a4b2c 100644 --- a/flag_test.go +++ b/flag_test.go @@ -2369,7 +2369,7 @@ func TestTimestampFlagApply_MultipleFormats(t *testing.T) { return errors.New("got nil err") } - found := regexp.MustCompile(`got nil/empty layouts slice"`).Match([]byte(err.Error())) + found := regexp.MustCompile(`got nil/empty layouts slice`).Match([]byte(err.Error())) if !found { return fmt.Errorf("given error does not satisfy pattern: %w", err) } @@ -2385,7 +2385,7 @@ func TestTimestampFlagApply_MultipleFormats(t *testing.T) { return errors.New("got nil err") } - found := regexp.MustCompile(`got nil/empty layouts slice"`).Match([]byte(err.Error())) + found := regexp.MustCompile(`got nil/empty layouts slice`).Match([]byte(err.Error())) if !found { return fmt.Errorf("given error does not satisfy pattern: %w", err) } @@ -2411,7 +2411,7 @@ func TestTimestampFlagApply_MultipleFormats(t *testing.T) { for idx := range testCases { testCase := testCases[idx] t.Run(testCase.caseName, func(t *testing.T) { - t.Parallel() + // t.Parallel() fl := TimestampFlag{ Name: "time", Config: TimestampConfig{ @@ -2422,6 +2422,13 @@ func TestTimestampFlagApply_MultipleFormats(t *testing.T) { set := flag.NewFlagSet("test", 0) _ = fl.Apply(set) + if len(testCase.layoutsPrecisions) == 0 { + err := set.Parse([]string{"--time", now.Format(time.RFC3339)}) + if testCase.expErrValidation != nil { + assert.NoError(t, testCase.expErrValidation(err)) + } + } + validLayouts := make([]string, 0, len(testCase.layoutsPrecisions)) invalidLayouts := make([]string, 0, len(testCase.layoutsPrecisions))