forked from Altinity/clickhouse-backup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
33 lines (29 loc) · 912 Bytes
/
utils_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
package main
import (
"log"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func timeParse(s string) time.Time {
t, err := time.Parse("2006-01-02T15-04-05", s)
if err != nil {
log.Fatal(err)
}
return t
}
func TestGetBackupsToDelete(t *testing.T) {
testData := []Backup{
Backup{Name: "three", Date: timeParse("2019-03-28T19-50-12")},
Backup{Name: "one", Date: timeParse("2019-01-28T19-50-12")},
Backup{Name: "five", Date: timeParse("2019-05-28T19-50-12")},
Backup{Name: "two", Date: timeParse("2019-02-28T19-50-12")},
Backup{Name: "four", Date: timeParse("2019-04-28T19-50-12")},
}
expectedData := []Backup{
Backup{Name: "two", Date: timeParse("2019-02-28T19-50-12")},
Backup{Name: "one", Date: timeParse("2019-01-28T19-50-12")},
}
assert.Equal(t, expectedData, GetBackupsToDelete(testData, 3))
assert.Equal(t, []Backup{}, GetBackupsToDelete([]Backup{testData[0]}, 3))
}