[test-improver] Improve tests for dockerutil package#1371
Merged
Conversation
- Add testify assert/require imports for idiomatic assertions - Replace manual length/element loop checks with assert.Equal - Use require.NoError for os.Setenv calls - Improve test case names to be more descriptive - Add new edge cases: nil args, empty args, -e with empty string arg, env value containing equals signs 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 test file for the dockerutil package by adopting project-wide testing conventions and adding edge case coverage. The changes migrate from manual two-step assertion patterns to the testify assertion library that is consistently used throughout the codebase, improving test maintainability and failure output clarity.
Changes:
- Adopted testify/assert and testify/require for cleaner assertions with better diff output on failure
- Improved test case names to be more descriptive of expected behavior
- Added four new edge case tests: nil args, empty args, empty string after -e flag, and env values containing equals signs
- Removed redundant comments that didn't add value beyond self-explanatory code
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced Feb 25, 2026
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/dockerutil/env_test.goFile Analyzed
internal/dockerutil/env_test.gointernal/dockerutilImprovements Made
1. Better Testing Patterns (Testify Assertions)
testify/assertandtestify/requireimportsassert.Equal(t, tt.expected, result)— cleaner and produces a better diff on failurerequire.NoError(t, os.Setenv(k, v))to surface Setenv failures instead of silently ignoring them2. Improved Test Case Names
"undefined env variable"→"undefined env variable leaves arg unchanged"(more descriptive of the expected behaviour)"empty env variable value"→"empty env variable value expands to key="(documents theKEY=format)3. Increased Coverage — New Edge Cases
nil args: passesnilas the args slice;ExpandEnvArgsshould return an empty (non-nil) sliceempty args: passes[]string{}; same expectation-e followed by empty string arg:-e ""— the empty-string next-arg must not trigger expansion (guarded bylen(nextArg) > 0)env value containing equals signs: value"a=b=c"must survive intact asKEY_WITH_EQUALS=a=b=c, confirming the implementation only checks the key for=, not the value4. Removed Redundant Comments
// Set up environment variables for testand// Clean up after test— the code is self-explanatory witht.CleanupWhy This File?
env_test.gowas the only test file in the project that still used a manual two-step assertion pattern (if len != len { Fatalf }+for range { Errorf }) instead of the project-wide testify convention. The file is small and self-contained, making it a safe, low-risk improvement with clear before/after value.Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests