-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
62 lines (51 loc) · 1.47 KB
/
types_test.go
File metadata and controls
62 lines (51 loc) · 1.47 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
package manager
import (
"testing"
"time"
)
func TestRuleStateCheck(t *testing.T) {
base := time.Date(2019, 03, 26, 8, 0, 0, 0, time.UTC)
rs := getSampleRuleState(nil)
mustBackup := rs.Check(base)
if mustBackup == true {
t.Fatal("RuleState with no next date should not trigger a backup, it must be set before")
}
old := time.Date(2019, 03, 24, 8, 0, 0, 0, time.UTC)
rs = getSampleRuleState(&old)
mustBackup = rs.Check(base)
if mustBackup == false {
t.Fatal("RuleState with an old next date should trigger a backup")
}
future := time.Date(2019, 03, 28, 8, 0, 0, 0, time.UTC)
rs = getSampleRuleState(&future)
mustBackup = rs.Check(base)
if mustBackup == true {
t.Fatal("RuleState with a future next date should not trigger a backup")
}
}
func TestFilesByDateDesc(t *testing.T) {
sampleFiles := getSampleFiles()
expected := []string{"file2", "file1", "file3"}
result := FilesSortedByDateDesc(sampleFiles)
for i := 0; i < len(sampleFiles); i++ {
if expected[i] != result[i].Path {
t.Fatalf("wrong order: got=%v expected=%v", result, expected)
}
}
}
func getSampleRuleState(next *time.Time) RuleState {
return RuleState{
Rule: Rule{
Count: 3,
MinAge: 1,
},
Next: next,
}
}
func getSampleFiles() []File {
return []File{
File{Path: "file1", Date: time.Date(2019, 03, 26, 8, 0, 0, 0, time.UTC)},
File{Path: "file2", Date: time.Date(2019, 03, 26, 10, 0, 0, 0, time.UTC)},
File{Path: "file3", Date: time.Date(2019, 03, 26, 6, 0, 0, 0, time.UTC)},
}
}