(t *testing.T)
| 12 | ) |
| 13 | |
| 14 | func TestLogsCommands(t *testing.T) { |
| 15 | t.Parallel() |
| 16 | |
| 17 | runner := testenv.NewInProcRunner(t) |
| 18 | e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) |
| 19 | |
| 20 | e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) |
| 21 | defer e.RunAndExpectSuccess(t, "repo", "disconnect") |
| 22 | |
| 23 | // one log from repository creation |
| 24 | e.RunAndVerifyOutputLineCount(t, 1, "logs", "list") |
| 25 | |
| 26 | // verify we did not add a log |
| 27 | e.RunAndVerifyOutputLineCount(t, 1, "logs", "list") |
| 28 | |
| 29 | e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t)) |
| 30 | |
| 31 | e.RunAndVerifyOutputLineCount(t, 2, "logs", "list") |
| 32 | |
| 33 | // sleep a bit so that 3rd log is reliably last in time order even if the clock is completely |
| 34 | // messed up. |
| 35 | time.Sleep(2 * time.Second) |
| 36 | e.RunAndExpectSuccess(t, "snapshot", "create", testutil.TempDirectory(t)) |
| 37 | |
| 38 | lines := e.RunAndVerifyOutputLineCount(t, 3, "logs", "list") |
| 39 | firstLogID := strings.Split(lines[0], " ")[0] |
| 40 | secondLogID := strings.Split(lines[1], " ")[0] |
| 41 | thirdLogID := strings.Split(lines[2], " ")[0] |
| 42 | |
| 43 | firstLogLines := e.RunAndExpectSuccess(t, "logs", "show", firstLogID) |
| 44 | secondLogLines := e.RunAndExpectSuccess(t, "logs", "show", secondLogID) |
| 45 | thirdLogLines := e.RunAndExpectSuccess(t, "logs", "show", thirdLogID) |
| 46 | e.RunAndExpectFailure(t, "logs", "show", "no-such-log") |
| 47 | |
| 48 | lines2 := e.RunAndVerifyOutputLineCount(t, 1, "logs", "list", "-n1") |
| 49 | require.Equal(t, thirdLogID, strings.Split(lines2[0], " ")[0]) |
| 50 | |
| 51 | e.RunAndVerifyOutputLineCount(t, 0, "logs", "list", "--younger-than=1ms") |
| 52 | e.RunAndVerifyOutputLineCount(t, 3, "logs", "list", "--younger-than=1h") |
| 53 | e.RunAndVerifyOutputLineCount(t, 3, "logs", "list", "--older-than=1ms") |
| 54 | e.RunAndVerifyOutputLineCount(t, 0, "logs", "list", "--older-than=1h") |
| 55 | |
| 56 | require.NotEqual(t, firstLogLines, secondLogLines) |
| 57 | require.NotEqual(t, secondLogLines, thirdLogLines) |
| 58 | |
| 59 | // by default cleanup retains a lot of logs. |
| 60 | e.RunAndExpectSuccess(t, "logs", "cleanup") |
| 61 | e.RunAndVerifyOutputLineCount(t, 3, "logs", "list") |
| 62 | e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=2", "--dry-run") |
| 63 | e.RunAndVerifyOutputLineCount(t, 3, "logs", "list") |
| 64 | e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=2") |
| 65 | e.RunAndVerifyOutputLineCount(t, 2, "logs", "list") |
| 66 | e.RunAndExpectSuccess(t, "logs", "cleanup", "--max-count=1") |
| 67 | e.RunAndVerifyOutputLineCount(t, 1, "logs", "list") |
| 68 | |
| 69 | // make sure latest log survived |
| 70 | e.RunAndExpectSuccess(t, "logs", "show", thirdLogID) |
| 71 | } |
nothing calls this directly
no test coverage detected