-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule_test.go
More file actions
70 lines (61 loc) · 1.87 KB
/
schedule_test.go
File metadata and controls
70 lines (61 loc) · 1.87 KB
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
package task
import (
"testing"
"time"
)
func TestEvery(t *testing.T) {
fn := Every(time.Second)
interval, err := fn(nil)
if err != nil {
t.Errorf("expected err to be nil")
}
if expected, actual := time.Second, interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
}
func TestEveryWithOption(t *testing.T) {
fn := Every(time.Second, SkipFirst)
interval, err := fn(nil)
if expected, actual := ErrSkip, err; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
if expected, actual := time.Second, interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
}
func TestBackoff(t *testing.T) {
fn := Backoff(time.Second)
interval, err := fn(nil)
if err != nil {
t.Errorf("expected err to be nil")
}
if expected, actual := time.Second, interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
}
func TestBackoffWithOption(t *testing.T) {
fn := Backoff(time.Second, Linear)
interval, err := fn(nil)
if expected, actual := true, err == nil; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
if expected, actual := time.Second, interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
for i := 1; i < 5; i++ {
interval, err = fn(ErrBackoff)
if expected, actual := true, err == nil; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
if expected, actual := time.Second*time.Duration(i), interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
}
interval, err = fn(nil)
if expected, actual := true, err == nil; expected != actual {
t.Errorf("expected: %v, actual: %v", expected, actual)
}
if expected, actual := time.Second, interval; expected != actual {
t.Errorf("expected: %d, actual: %d", expected, actual)
}
}