Repository navigation
[test-improver] Improve tests for tty package - #1632
Closed
github-actions[bot] wants to merge 1 commit into
Closed
github-actions[bot] wants to merge 1 commit into
github-actions[bot] wants to merge 1 commit into
Conversation
- Add clearContainerEnv helper to replace repeated 6-line env save/restore boilerplate - Use t.Setenv() for env var setup in subtests (idiomatic, auto-cleanup) - Use clearContainerEnv() for 'unset' cases (TestIsRunningInContainer_FileBasedDetection, TestIsRunningInContainer_Consistency, TestIsRunningInContainer_ConcurrentAccess, and per-subtest in TestIsRunningInContainer_EnvironmentVariable) - Remove top-level env save/restore in TestIsRunningInContainer_EdgeCases by moving t.Setenv() into each subtest (proper test isolation) - Add TestIsStderrTerminal to cover the previously untested IsStderrTerminal() function in tty.go Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced Mar 6, 2026
lpcox
deleted the
test-improver/tty-container-test-improvements-11cd950d7850005b
branch
March 21, 2026 14:54
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: container_test.go
File Analyzed
internal/tty/container_test.gointernal/ttyImprovements Made
1. Better Testing Patterns
clearContainerEnvhelper — extracts the repeated 6-lineos.LookupEnv+defersave/restore block used 5 times in the file into a single reusablet.Cleanup-based helpert.Setenvfor all test cases that setRUNNING_IN_CONTAINERto a specific value — this is idiomatic Go since Go 1.17, provides automatic cleanup even on panic, and eliminates manual teardownTestIsRunningInContainer_EdgeCases— movedt.Setenv()into each subtest instead of relying on a top-leveldefershared across subtests (safer, enables potential futuret.Parallel())2. Increased Coverage
TestIsStderrTerminal— covers the previously untestedIsStderrTerminal()function intty.go. The function wrapsterm.IsTerminalforos.Stderrand had no test coverage. The new test verifies the function is deterministic (returns the same value on repeated calls) without panicking.3. Cleaner & More Stable Tests
clearContainerEnv(t)(1 line) ort.Setenv(...)(1 line)t.Helper()inclearContainerEnvfor cleaner failure outputTestIsRunningInContainer_EdgeCasessubtests now each own their environment setup viat.Setenv, rather than sharing state through a top-leveldeferTest Execution
All existing tests preserved. The changes are semantically equivalent for all existing test logic —
t.SetenvandclearContainerEnvprovide the same save/restore semantics as the originalos.LookupEnv/deferpattern, but more idiomatically.Why These Changes?
internal/tty/container_test.gowas selected because:os.LookupEnv+defer) in 5 places — a clear candidate fort.Setenvand a helpertty.gohad an untested function (IsStderrTerminal) — a clear coverage gapGenerated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests