MCPcopy Create free account
hub / github.com/containerd/nerdctl / TestLogsTailFollowRotate

Function TestLogsTailFollowRotate

cmd/nerdctl/container/container_logs_test.go:439–483  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

437}
438
439func 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
485func TestLogsNoneLoggerHasNoLogURI(t *testing.T) {
486 testCase := nerdtest.Setup()

Callers

nothing calls this directly

Calls 8

SetupFunction · 0.92
AssertMethod · 0.80
EnsureMethod · 0.65
IdentifierMethod · 0.65
AnyhowMethod · 0.65
CommandMethod · 0.65
WithTimeoutMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…