-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers_test.go
52 lines (42 loc) · 1.17 KB
/
helpers_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
package main
import (
"sort"
"testing"
"time"
)
func TestParseDuration(t *testing.T) {
tests := map[string]time.Duration{
"1s": time.Duration(1) * time.Second,
"2m": time.Duration(2) * time.Minute,
"3h": time.Duration(3) * time.Hour,
"5d": time.Duration(5*24) * time.Hour,
"2w": time.Duration(2*7*24) * time.Hour,
"2mo": time.Duration(2*30*24) * time.Hour,
}
for s, d := range tests {
actual, err := parseDuration(s)
if err != nil {
t.Errorf("Failed to parse duration %s", err.Error())
}
if d != actual {
t.Errorf("Expected time string %s to be duration %v, got %v", s, d, actual)
}
}
bad, err := parseDuration("someotherstring")
if err == nil {
t.Errorf("Expected error from bad string to not be nil, got duration %v", bad)
}
}
func TestBySchedule(t *testing.T) {
l := []string{"1w", "2d", "10s", "3s", "1mo", "27d"}
expected := []string{"3s", "10s", "2d", "1w", "27d", "1mo"}
sort.Sort(BySchedule(l))
if len(l) != len(expected) {
t.Errorf("Expected lengths to be equal after sort. Expected: %d, got: %d", len(expected), len(l))
}
for i, v := range expected {
if v != l[i] {
t.Errorf("Expected %s, got %s", v, l[i])
}
}
}