(t *testing.T)
| 41 | } |
| 42 | |
| 43 | func TestExtendedParseDuration(t *testing.T) { |
| 44 | t.Parallel() |
| 45 | for _, testCase := range []struct { |
| 46 | Duration string |
| 47 | Expected time.Duration |
| 48 | ExpectedOk bool |
| 49 | }{ |
| 50 | {"1d", 24 * time.Hour, true}, |
| 51 | {"1y", 365 * 24 * time.Hour, true}, |
| 52 | {"10s", 10 * time.Second, true}, |
| 53 | {"1m", 1 * time.Minute, true}, |
| 54 | {"20h", 20 * time.Hour, true}, |
| 55 | {"10y10d10s", 10*365*24*time.Hour + 10*24*time.Hour + 10*time.Second, true}, |
| 56 | {"10ms", 10 * time.Millisecond, true}, |
| 57 | {"5y10d10s5y2ms8ms", 10*365*24*time.Hour + 10*24*time.Hour + 10*time.Second + 10*time.Millisecond, true}, |
| 58 | {"10yz10d10s", 0, false}, |
| 59 | {"1µs2h1d", 1*time.Microsecond + 2*time.Hour + 1*24*time.Hour, true}, |
| 60 | {"1y365d", 2 * 365 * 24 * time.Hour, true}, |
| 61 | {"1µs10us", 1*time.Microsecond + 10*time.Microsecond, true}, |
| 62 | // negative related tests |
| 63 | {"-", 0, false}, |
| 64 | {"-2h10m", -2*time.Hour - 10*time.Minute, true}, |
| 65 | {"--10s", 0, false}, |
| 66 | {"10s-10m", 0, false}, |
| 67 | // overflow related tests |
| 68 | {"-20000000000000h", 0, false}, |
| 69 | {"92233754775807y", 0, false}, |
| 70 | {"200y200y200y200y200y", 0, false}, |
| 71 | {"9223372036854775807s", 0, false}, |
| 72 | } { |
| 73 | t.Run(testCase.Duration, func(t *testing.T) { |
| 74 | t.Parallel() |
| 75 | actual, err := extendedParseDuration(testCase.Duration) |
| 76 | if testCase.ExpectedOk { |
| 77 | require.NoError(t, err) |
| 78 | assert.Equal(t, testCase.Expected, actual) |
| 79 | } else { |
| 80 | assert.Error(t, err) |
| 81 | } |
| 82 | }) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | func TestRelative(t *testing.T) { |
| 87 | t.Parallel() |
nothing calls this directly
no test coverage detected