MCPcopy
hub / github.com/kopia/kopia / TestRestoreSnapshotMaxTime

Function TestRestoreSnapshotMaxTime

cli/command_restore_test.go:12–50  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

10)
11
12func TestRestoreSnapshotMaxTime(t *testing.T) {
13 t.Parallel()
14
15 now := clock.Now()
16 ago := func(y, m, d int) time.Time {
17 r := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
18 return r.AddDate(y, m, d)
19 }
20 at := func(y, mo, d, h, m, s int) time.Time {
21 return time.Date(y, time.Month(mo), d, h, m, s, 0, now.Location())
22 }
23
24 requireTime := func(expected time.Time, timespec string) {
25 mt, err := computeMaxTime(timespec)
26 require.NoError(t, err)
27 require.Equal(t, expected, mt)
28 }
29
30 requireTime(ago(0, 0, 0), "yesterday")
31 requireTime(ago(0, 0, 0), "1d-ago")
32 requireTime(ago(0, 0, 0), "1day-ago")
33
34 requireTime(at(now.Year(), int(now.Month()), 1, 0, 0, 0), "last-month")
35 requireTime(at(now.Year(), 1, 1, 0, 0, 0), "last-year")
36
37 requireTime(ago(0, -1, 1), "1month-ago")
38 requireTime(ago(0, -1, 1), "1m-ago")
39 requireTime(ago(-1, 0, 1), "1year-ago")
40 requireTime(ago(-1, 0, 1), "1y-ago")
41 requireTime(ago(-2, -2, -1), "2years-2months-2days-ago")
42 requireTime(ago(-2, -2, -1), "2y-2m-2d-ago")
43
44 requireTime(at(2020, 1, 1, 0, 0, 0), "2019")
45 requireTime(at(2019, 2, 1, 0, 0, 0), "2019-1")
46 requireTime(at(2019, 1, 2, 0, 0, 0), "2019-01-1")
47 requireTime(at(2019, 1, 1, 14, 0, 0), "2019-01-1 13")
48 requireTime(at(2019, 1, 1, 13, 2, 0), "2019-01-1 13:01")
49 requireTime(at(2019, 1, 1, 13, 1, 16), "2019-01-1 13:01:15")
50}
51
52func TestRestoreSnapshotFilter(t *testing.T) {
53 f, err := createSnapshotTimeFilter("latest")

Callers

nothing calls this directly

Calls 3

NowFunction · 0.92
computeMaxTimeFunction · 0.85
EqualMethod · 0.80

Tested by

no test coverage detected