-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob_base_test.go
70 lines (63 loc) · 1.25 KB
/
job_base_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-FileCopyrightText: 2021 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package karajo
import (
"testing"
"time"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestJobBase_computeNextInterval(t *testing.T) {
type testCase struct {
jobHTTP *JobHTTP
desc string
exp time.Duration
}
var (
now = time.Date(2021, 3, 6, 14, 0, 0, 0, time.UTC)
interval = 30 * time.Second
)
var cases = []testCase{{
desc: `Last run is -2*interval`,
jobHTTP: &JobHTTP{
JobBase: JobBase{
LastRun: now.Add(-2 * interval),
Interval: interval,
},
},
}, {
desc: `Last run is now`,
jobHTTP: &JobHTTP{
JobBase: JobBase{
LastRun: now.UTC(),
Interval: interval,
},
},
exp: interval,
}, {
desc: `Last run is half-interval ago`,
jobHTTP: &JobHTTP{
JobBase: JobBase{
LastRun: now.Add(-1 * (interval / 2)),
Interval: interval,
},
},
exp: interval / 2,
}, {
desc: `Last run > now?`,
jobHTTP: &JobHTTP{
JobBase: JobBase{
LastRun: now.Add(1 * interval),
Interval: interval,
},
},
exp: 2 * interval,
}}
var (
c testCase
got time.Duration
)
for _, c = range cases {
got = c.jobHTTP.computeNextInterval(now)
test.Assert(t, c.desc, c.exp, got)
}
}