(t *testing.T)
| 21 | ) |
| 22 | |
| 23 | func TestParseDuration(t *testing.T) { |
| 24 | const day = 24 * time.Hour |
| 25 | for i, tc := range []struct { |
| 26 | input string |
| 27 | expect time.Duration |
| 28 | }{ |
| 29 | { |
| 30 | input: "3h", |
| 31 | expect: 3 * time.Hour, |
| 32 | }, |
| 33 | { |
| 34 | input: "1d", |
| 35 | expect: day, |
| 36 | }, |
| 37 | { |
| 38 | input: "1d30m", |
| 39 | expect: day + 30*time.Minute, |
| 40 | }, |
| 41 | { |
| 42 | input: "1m2d", |
| 43 | expect: time.Minute + day*2, |
| 44 | }, |
| 45 | { |
| 46 | input: "1m2d30s", |
| 47 | expect: time.Minute + day*2 + 30*time.Second, |
| 48 | }, |
| 49 | { |
| 50 | input: "1d2d", |
| 51 | expect: 3 * day, |
| 52 | }, |
| 53 | { |
| 54 | input: "1.5d", |
| 55 | expect: time.Duration(1.5 * float64(day)), |
| 56 | }, |
| 57 | { |
| 58 | input: "4m1.25d", |
| 59 | expect: 4*time.Minute + time.Duration(1.25*float64(day)), |
| 60 | }, |
| 61 | { |
| 62 | input: "-1.25d12h", |
| 63 | expect: time.Duration(-1.25*float64(day)) - 12*time.Hour, |
| 64 | }, |
| 65 | } { |
| 66 | actual, err := ParseDuration(tc.input) |
| 67 | if err != nil { |
| 68 | t.Errorf("Test %d ('%s'): Got error: %v", i, tc.input, err) |
| 69 | continue |
| 70 | } |
| 71 | if actual != tc.expect { |
| 72 | t.Errorf("Test %d ('%s'): Expected=%s Actual=%s", i, tc.input, tc.expect, actual) |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | func TestEvent_CloudEvent_NilOrigin(t *testing.T) { |
| 78 | ctx, _ := NewContext(Context{Context: context.Background()}) // module will be nil by default |
nothing calls this directly
no test coverage detected