[test-improver] Improve tests for cmd/flags_logging#6871
Merged
lpcox merged 2 commits intoJun 2, 2026
Conversation
- Replace manual os.LookupEnv/Setenv/Unsetenv cleanup with t.Setenv for cleaner, safer test teardown - Add missing edge case: whitespace-only env var should fall back to log-dir default (tests the trimmed != "" branch in resolveWasmCacheDir) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Updates internal/cmd/flags_logging_test.go to simplify environment variable setup/teardown and add coverage for the whitespace-only env-var path when resolving the WASM cache directory.
Changes:
- Replace manual
os.LookupEnv/t.Cleanup/os.Unsetenvboilerplate witht.Setenvin relevant subtests. - Add a new subtest covering whitespace-only
MCP_GATEWAY_WASM_CACHE_DIRfalling back to the default cache dir.
Show a summary per file
| File | Description |
|---|---|
| internal/cmd/flags_logging_test.go | Refactors env-var handling to t.Setenv and adds a whitespace-only env-var test case for resolveWasmCacheDir. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 1/1 changed files
- Comments generated: 1
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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: flags_logging_test.go
File Analyzed
internal/cmd/flags_logging_test.gointernal/cmdImprovements Made
1. Better Testing Patterns
os.LookupEnv/os.Setenv/os.Unsetenvboilerplate (3 calls +t.Cleanup) witht.Setenv— which handles setup and restore automatically2. Increased Coverage
strings.TrimSpace(envValue) != ""branch inresolveWasmCacheDirwhen the env var is set to whitespace (e.g." "), which was previously untestedTestResolveWasmCacheDirsubtests: 7 → 83. Cleaner & More Stable Tests
t.Setenvguarantees automatic cleanup even if the test panics, unlike the manualt.Cleanup+os.Setenv/os.Unsetenvpatternt.Setenvscope)Test Execution
All tests pass:
Why These Changes?
The two
os.Unsetenvtest cases were using a 7-line manual env save/restore pattern that is verbose, error-prone (must restore int.Cleanup, easy to forget), and doesn't benefit fromtesting.T's built-in env management. Usingt.Setenv(key, "")achieves the same observable behavior (the function checkstrimmed != ""afterstrings.TrimSpace, so an empty string and an unset var both fall through to the default path).The new whitespace-only env var test ensures the
strings.TrimSpaceguard inresolveWasmCacheDiris exercised for the env-var code path, complementing the existing whitespace-only flag test.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
index.crates.ioSee Network Configuration for more information.