{{ message }}
[test-improver] Improve tests for sys package#7848
Merged
Conversation
- Add t.Parallel() to TestExtractContainerIDFromContent and all subtests - Add t.Parallel() to TestContainsAny_Helper and all subtests - Add t.Parallel() to all TestExtractContainerIDFromCgroupFiles_* tests - Add scanner-overflow test case (bufio.MaxScanTokenSize+1 line) to cover the scanner.Err() != nil path in extractContainerIDFromContent Coverage: internal/sys 98.9% -> 100.0% Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the internal/sys test suite by adding explicit coverage for an edge-case error path in container ID parsing and by enabling parallel execution for tests that are safe to run concurrently. This helps keep the sys package’s tests more robust while reducing overall test wall-clock time.
Changes:
- Added a new test case to exercise the
bufio.Scanneroverflow/error branch inextractContainerIDFromContent. - Marked pure-function / temp-file-only tests as parallelizable via
t.Parallel()(including table subtests).
Show a summary per file
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This was referenced Jun 21, 2026
Collaborator
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Test Improvements:
internal/sys/container_test.go+container_detect_test.goFile Analyzed
internal/sys/container_test.go,internal/sys/container_detect_test.gointernal/sysImprovements Made
1. Scanner-overflow coverage (new test case)
Added a test case
"single line exceeding scanner buffer limit returns empty string"toTestExtractContainerIDFromContent. This covers the previously-untestedscanner.Err() != nilbranch inextractContainerIDFromContent(triggered when a single line exceedsbufio.MaxScanTokenSize= 65,536 bytes):{ name: "single line exceeding scanner buffer limit returns empty string", input: strings.Repeat("x", bufio.MaxScanTokenSize+1), want: "", },2. Parallel test execution
Added
t.Parallel()to all pure-function tests (safe to run concurrently — no environment mutation, no shared state):TestExtractContainerIDFromContent+ all 16 subtestsTestContainsAny_Helper+ all subtestsTestExtractContainerIDFromCgroupFiles_*tests incontainer_detect_test.go(temp-file only, not.Setenv)3. Increased Coverage
extractContainerIDFromContent→ 92.3%, package total → 98.9%extractContainerIDFromContent→ 100.0%, package total → 100.0%Test Execution
All tests pass with
-raceflag enabled. Tests run multiple times with consistent results.Why These Changes?
extractContainerIDFromContentusedbufio.Scannerto parse cgroup content but the error path (scanner.Err() != nil) was never exercised — it requires a line longer than 64 KiB, an unusual but valid edge case. Adding the overflow test ensures the error path is verified. The parallelism additions are low-risk improvements to pure-function tests, reducing wall-clock test time with no behavior changes.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests