Skip to content

Commit

Permalink
test: fix tests to cover empty layout scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
horockey committed Aug 7, 2024
1 parent bf82dab commit 9c9d13e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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{
Expand All @@ -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))

Expand Down

0 comments on commit 9c9d13e

Please sign in to comment.