Skip to content

[test-improver] Improve tests for dockerutil package#1371

Merged
lpcox merged 1 commit intomainfrom
test-improver/dockerutil-env-testify-01c4f31f2488a2c0
Feb 25, 2026
Merged

[test-improver] Improve tests for dockerutil package#1371
lpcox merged 1 commit intomainfrom
test-improver/dockerutil-env-testify-01c4f31f2488a2c0

Conversation

@github-actions
Copy link
Contributor

Test Improvements: internal/dockerutil/env_test.go

File Analyzed

  • Test File: internal/dockerutil/env_test.go
  • Package: internal/dockerutil
  • Lines of Code: 91 → 107

Improvements Made

1. Better Testing Patterns (Testify Assertions)

  • ✅ Added testify/assert and testify/require imports
  • ✅ Replaced manual length-check + element-by-element loop with single assert.Equal(t, tt.expected, result) — cleaner and produces a better diff on failure
  • ✅ Used require.NoError(t, os.Setenv(k, v)) to surface Setenv failures instead of silently ignoring them

2. Improved Test Case Names

  • ✅ Renamed "undefined env variable""undefined env variable leaves arg unchanged" (more descriptive of the expected behaviour)
  • ✅ Renamed "empty env variable value""empty env variable value expands to key=" (documents the KEY= format)

3. Increased Coverage — New Edge Cases

  • nil args: passes nil as the args slice; ExpandEnvArgs should return an empty (non-nil) slice
  • empty args: passes []string{}; same expectation
  • -e followed by empty string arg: -e "" — the empty-string next-arg must not trigger expansion (guarded by len(nextArg) > 0)
  • env value containing equals signs: value "a=b=c" must survive intact as KEY_WITH_EQUALS=a=b=c, confirming the implementation only checks the key for =, not the value

4. Removed Redundant Comments

  • ✅ Removed // Set up environment variables for test and // Clean up after test — the code is self-explanatory with t.Cleanup

Why This File?

env_test.go was 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

AI generated by Test Improver

- 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>
@lpcox lpcox marked this pull request as ready for review February 25, 2026 00:55
Copilot AI review requested due to automatic review settings February 25, 2026 00:55
@lpcox lpcox merged commit 27e173f into main Feb 25, 2026
2 checks passed
@lpcox lpcox deleted the test-improver/dockerutil-env-testify-01c4f31f2488a2c0 branch February 25, 2026 00:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants