/
rotate_test.go
84 lines (73 loc) · 1.4 KB
/
rotate_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package rotatesnapshot
import (
"fmt"
"testing"
"time"
)
const (
HourlyTest = "hourly"
DailyTest = "daily"
WeeklyTest = "weekly"
MonthlyTest = "monthly"
)
type FakeProvider struct {
duration string
}
func (f *FakeProvider) ListSnapshots() ([]Snapshot, error) {
var s []Snapshot
var count int
n := "snapshot"
now := time.Now()
switch f.duration {
case HourlyTest:
count = 24
case DailyTest:
count = 24 * 7
case WeeklyTest:
count = 24 * 7 * 4
case MonthlyTest:
count = 24 * 7 * 4 * 3
}
var t time.Time
for count > 0 {
t = now.Add(time.Duration(-count) * time.Hour)
s = append(s, Snapshot{Name: fmt.Sprintf("%s-%v", n, t.Format("20060102150405")), CreateTime: t})
count--
}
return s, nil
}
func (f *FakeProvider) DeleteSnapshots(s []string) error {
return nil
}
func TestRotate(t *testing.T) {
verbose = true
type args struct {
p Provider
}
tests := []struct {
name string
args args
}{
{
name: "test hourly rotation",
args: args{p: &FakeProvider{duration: HourlyTest}},
},
{
name: "test daily rotation",
args: args{p: &FakeProvider{duration: DailyTest}},
},
{
name: "test weekly rotation",
args: args{p: &FakeProvider{duration: WeeklyTest}},
},
{
name: "test montly rotation",
args: args{p: &FakeProvider{duration: MonthlyTest}},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Rotate(tt.args.p)
})
}
}