(t *testing.T)
| 437 | } |
| 438 | |
| 439 | func TestLogsTailFollowRotate(t *testing.T) { |
| 440 | // FIXME this is flaky by nature... the number of lines is arbitrary, the wait is arbitrary, |
| 441 | // and both are some sort of educated guess that things will mostly always kinda work maybe... |
| 442 | const sampleJSONLog = `{"log":"A\n","stream":"stdout","time":"2024-04-11T12:01:09.800288974Z"}` |
| 443 | const linesPerFile = 200 |
| 444 | |
| 445 | testCase := nerdtest.Setup() |
| 446 | |
| 447 | // tail log is not supported on Windows |
| 448 | testCase.Require = require.Not(require.Windows) |
| 449 | |
| 450 | testCase.Setup = func(data test.Data, helpers test.Helpers) { |
| 451 | helpers.Ensure("run", "-d", "--log-driver", "json-file", |
| 452 | "--log-opt", fmt.Sprintf("max-size=%d", len(sampleJSONLog)*linesPerFile), |
| 453 | "--log-opt", "max-file=10", |
| 454 | "--name", data.Identifier(), testutil.CommonImage, |
| 455 | "sh", "-euc", "while true; do echo A; usleep 100; done") |
| 456 | // FIXME: ... inherently racy... |
| 457 | time.Sleep(5 * time.Second) |
| 458 | } |
| 459 | |
| 460 | testCase.Cleanup = func(data test.Data, helpers test.Helpers) { |
| 461 | helpers.Anyhow("rm", "-f", data.Identifier()) |
| 462 | } |
| 463 | |
| 464 | testCase.Command = func(data test.Data, helpers test.Helpers) test.TestableCommand { |
| 465 | cmd := helpers.Command("logs", "-f", data.Identifier()) |
| 466 | // FIXME: this is flaky by nature. We assume that the container has started and will output enough in 5 seconds. |
| 467 | cmd.WithTimeout(5 * time.Second) |
| 468 | return cmd |
| 469 | } |
| 470 | |
| 471 | testCase.Expected = test.Expects(expect.ExitCodeTimeout, nil, func(stdout string, t tig.T) { |
| 472 | tailLogs := strings.Split(strings.TrimSpace(stdout), "\n") |
| 473 | for _, line := range tailLogs { |
| 474 | if line != "" { |
| 475 | assert.Equal(t, "A", line) |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | assert.Assert(t, len(tailLogs) > linesPerFile, fmt.Sprintf("expected %d lines or more, found %d", linesPerFile, len(tailLogs))) |
| 480 | }) |
| 481 | |
| 482 | testCase.Run(t) |
| 483 | } |
| 484 | |
| 485 | func TestLogsNoneLoggerHasNoLogURI(t *testing.T) { |
| 486 | testCase := nerdtest.Setup() |
nothing calls this directly
no test coverage detected
searching dependent graphs…