forked from sstark/snaprd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschedules_test.go
70 lines (62 loc) · 1.3 KB
/
schedules_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
/* See the file "LICENSE.txt" for the full license governing this code. */
package main
import (
"reflect"
"testing"
"time"
)
var testSchedules = scheduleList{
"testSched1": {second, second * 2, second * 4, second * 8, second * 16, long},
}
type offsetTestPair struct {
i int
seconds int64
}
func TestScheduleOffset(t *testing.T) {
var tests = []offsetTestPair{
{0, 0},
{1, 2},
{2, 6},
{3, 14},
{4, 30},
{5, 3153600030},
}
for _, pair := range tests {
v := int64(testSchedules["testSched1"].offset(pair.i).Seconds())
if v != pair.seconds {
t.Errorf("offset(%v) got %v, expected %v", pair.i, v, pair.seconds)
}
}
}
type goalTestPair struct {
i int
goal int
}
func TestScheduleGoal(t *testing.T) {
var tests = []goalTestPair{
{0, 2},
{1, 2},
{2, 2},
{3, 2},
{4, 197100000},
}
for _, pair := range tests {
v := testSchedules["testSched1"].goal(pair.i)
if v != pair.goal {
t.Errorf("goal(%v) got %v, expected %v", pair.i, v, pair.goal)
}
}
}
func TestSchedulesAddFromFile(t *testing.T) {
schedules.addFromFile("testdata/snaprd.schedules")
wanted := intervalList{
time.Hour * 24,
time.Hour * 168,
time.Hour * 672,
time.Hour * 876000,
}
got := schedules["test1"]
if !reflect.DeepEqual(got, wanted) {
t.Errorf("wanted %v, got %v", wanted, got)
}
}