forked from wal-g/wal-g
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility_test.go
55 lines (49 loc) · 1.23 KB
/
utility_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
package walg_test
import (
"github.com/wal-g/wal-g"
"sort"
"testing"
"time"
)
var times = []struct {
input walg.BackupTime
}{
{walg.BackupTime{
Name: "second",
Time: time.Date(2017, 2, 2, 30, 48, 39, 651387233, time.UTC),
WalFileName: "",
}},
{walg.BackupTime{
Name: "fourth",
Time: time.Date(2009, 2, 27, 20, 8, 33, 651387235, time.UTC),
WalFileName: "",
}},
{walg.BackupTime{
Name: "fifth",
Time: time.Date(2008, 11, 20, 16, 34, 58, 651387232, time.UTC),
WalFileName: "",
}},
{walg.BackupTime{
Name: "first",
Time: time.Date(2020, 11, 31, 20, 3, 58, 651387237, time.UTC),
WalFileName: "",
}},
{walg.BackupTime{
Name: "third",
Time: time.Date(2009, 3, 13, 4, 2, 42, 651387234, time.UTC),
WalFileName: "",
}},
}
func TestSortLatestTime(t *testing.T) {
correct := [5]string{"first", "second", "third", "fourth", "fifth"}
sortTimes := make([]walg.BackupTime, 5)
for i, val := range times {
sortTimes[i] = val.input
}
sort.Sort(walg.TimeSlice(sortTimes))
for i, val := range sortTimes {
if val.Name != correct[i] {
t.Errorf("utility: Sort times expected %v as %s but got %s instead", val.Time, correct[i], val.Name)
}
}
}