forked from kopia/kopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand_logs_test.go
More file actions
128 lines (94 loc) · 4.51 KB
/
Copy pathcommand_logs_test.go
File metadata and controls
128 lines (94 loc) · 4.51 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package cli_test
import (
"strings"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/kopia/kopia/internal/testutil"
"github.com/kopia/kopia/tests/testenv"
)
func TestLogsCommands(t *testing.T) {
t.Parallel()
runner := testenv.NewInProcRunner(t)
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
defer e.RunAndExpectSuccess(t, "repo", "disconnect")
// one log from repository creation
e.RunAndVerifyOutputLineCount(t, 1, "logs", "list")
// verify we did not add a log
e.RunAndVerifyOutputLineCount(t, 1, "logs", "list")
e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t))
e.RunAndVerifyOutputLineCount(t, 2, "logs", "list")
// sleep a bit so that 3rd log is reliably last in time order even if the clock is completely
// messed up.
time.Sleep(2 * time.Second)
e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t))
lines := e.RunAndVerifyOutputLineCount(t, 3, "logs", "list")
firstLogID := strings.Split(lines[0], " ")[0]
secondLogID := strings.Split(lines[1], " ")[0]
thirdLogID := strings.Split(lines[2], " ")[0]
firstLogLines := e.RunAndExpectSuccess(t, "logs", "show", firstLogID)
secondLogLines := e.RunAndExpectSuccess(t, "logs", "show", secondLogID)
thirdLogLines := e.RunAndExpectSuccess(t, "logs", "show", thirdLogID)
e.RunAndExpectFailure(t, "logs", "show", "no-such-log")
lines2 := e.RunAndVerifyOutputLineCount(t, 1, "logs", "list", "-n1")
require.Equal(t, thirdLogID, strings.Split(lines2[0], " ")[0])
e.RunAndVerifyOutputLineCount(t, 0, "logs", "list", "--younger-than=1ms")
e.RunAndVerifyOutputLineCount(t, 3, "logs", "list", "--younger-than=1h")
e.RunAndVerifyOutputLineCount(t, 3, "logs", "list", "--older-than=1ms")
e.RunAndVerifyOutputLineCount(t, 0, "logs", "list", "--older-than=1h")
require.NotEqual(t, firstLogLines, secondLogLines)
require.NotEqual(t, secondLogLines, thirdLogLines)
// by default cleanup retains a lot of logs.
e.RunAndExpectSuccess(t, "logs", "cleanup")
e.RunAndVerifyOutputLineCount(t, 3, "logs", "list")
e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=2", "--dry-run")
e.RunAndVerifyOutputLineCount(t, 3, "logs", "list")
e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=2")
e.RunAndVerifyOutputLineCount(t, 2, "logs", "list")
e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=1")
e.RunAndVerifyOutputLineCount(t, 1, "logs", "list")
// make sure latest log survived
e.RunAndExpectSuccess(t, "logs", "show", thirdLogID)
}
func TestLogsMaintenance(t *testing.T) {
t.Parallel()
runner := testenv.NewInProcRunner(t)
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
defer e.RunAndExpectSuccess(t, "repo", "disconnect")
time.Sleep(time.Second)
e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t))
time.Sleep(time.Second)
e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t))
time.Sleep(time.Second)
e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t))
e.RunAndVerifyOutputLineCount(t, 4, "logs", "list")
e.RunAndExpectSuccess(t, "maintenance", "set", "--max-retained-log-count=2")
e.RunAndVerifyOutputLineCount(t, 5, "logs", "list")
e.RunAndExpectSuccess(t, "maintenance", "run", "--full")
// maintenance run will create a new log and keep previous 2 logs
e.RunAndVerifyOutputLineCount(t, 3, "logs", "list")
e.RunAndExpectSuccess(t, "maintenance", "set", "--max-retained-log-age=1ms")
// maintenance does not run here
e.RunAndVerifyOutputLineCount(t, 4, "logs", "list")
e.RunAndExpectSuccess(t, "maintenance", "run", "--full")
// maintenance run will create a new log and delete all previous logs
e.RunAndVerifyOutputLineCount(t, 1, "logs", "list")
}
func TestLogsMaintenanceSet(t *testing.T) {
t.Parallel()
runner := testenv.NewInProcRunner(t)
e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
defer e.RunAndExpectSuccess(t, "repo", "disconnect")
e.RunAndExpectSuccess(t, "maintenance", "set",
"--max-retained-log-age=22h",
"--max-retained-log-size-mb=33",
"--max-retained-log-count=44",
)
infoLines := e.RunAndExpectSuccess(t, "maintenance", "info")
require.Contains(t, infoLines, " max age of logs: 22h0m0s")
require.Contains(t, infoLines, " max total size: 34.6 MB")
require.Contains(t, infoLines, " max count: 44")
}