MCPcopy
hub / github.com/urfave/cli / TestTimestampFlagApply_MultipleFormats

Function TestTimestampFlagApply_MultipleFormats

flag_test.go:2505–2674  ·  flag_test.go::TestTimestampFlagApply_MultipleFormats
(t *testing.T)

Source from the content-addressed store, hash-verified

2503}
2504
2505func TestTimestampFlagApply_MultipleFormats(t *testing.T) {
2506 now := time.Now().UTC()
2507
2508 testCases := []struct {
2509 caseName string
2510 layoutsPrecisions map[string]time.Duration
2511 expRes time.Time
2512 expErrValidation func(err error) (validation error)
2513 }{
2514 {
2515 caseName: "all_valid_layouts",
2516 layoutsPrecisions: map[string]time.Duration{
2517 time.RFC3339: time.Second,
2518 time.DateTime: time.Second,
2519 time.RFC1123: time.Second,
2520 },
2521 expRes: now.Truncate(time.Second),
2522 },
2523 {
2524 caseName: "one_invalid_layout",
2525 layoutsPrecisions: map[string]time.Duration{
2526 time.RFC3339: time.Second,
2527 time.DateTime: time.Second,
2528 "foo": 0,
2529 },
2530 expRes: now.Truncate(time.Second),
2531 },
2532 {
2533 caseName: "multiple_invalid_layouts",
2534 layoutsPrecisions: map[string]time.Duration{
2535 time.RFC3339: time.Second,
2536 "foo": 0,
2537 time.DateTime: time.Second,
2538 "bar": 0,
2539 },
2540 expRes: now.Truncate(time.Second),
2541 },
2542 {
2543 caseName: "all_invalid_layouts",
2544 layoutsPrecisions: map[string]time.Duration{
2545 "foo": 0,
2546 "2024-08-07 74:01:82Z-100": 0,
2547 "25:70": 0,
2548 "": 0,
2549 },
2550 expErrValidation: func(err error) error {
2551 if err == nil {
2552 return errors.New("got nil err")
2553 }
2554
2555 found := regexp.MustCompile(`(cannot parse ".+" as ".*")|(extra text: ".+")`).Match([]byte(err.Error()))
2556 if !found {
2557 return fmt.Errorf("given error does not satisfy pattern: %w", err)
2558 }
2559
2560 return nil
2561 },
2562 },

Callers

nothing calls this directly

Calls 6

SetMethod · 0.65
FormatMethod · 0.65
ParseMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected