[test-improver] Improve tests for envutil package#6960
Merged
lpcox merged 1 commit intoJun 4, 2026
Conversation
Add TestLoadEnvFile_EmptyKey to cover the error branch triggered when
a line with an empty key (e.g. "=value") is encountered. os.Setenv("", ...)
returns an invalid-argument error on Linux, which LoadEnvFile wraps and
returns. This branch was previously uncovered, bringing envfile.go coverage
from 95.7% to 100% (package: 99.2% → 100%).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves test coverage for the internal/envutil package by adding a focused unit test that exercises the os.Setenv failure path in LoadEnvFile when an env file line has an empty key.
Changes:
- Added
TestLoadEnvFile_EmptyKeyto assertLoadEnvFilereturns an error for a line like=somevalue. - Verified the returned error includes the wrapper message
"failed to set"used byLoadEnvFile.
Show a summary per file
| File | Description |
|---|---|
| internal/envutil/envfile_test.go | Adds a new test to cover the os.Setenv error branch in LoadEnvFile for empty-key entries. |
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: 0
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.
File Analyzed
internal/envutil/envfile_test.gointernal/envutilImprovements Made
1. Increased Coverage
TestLoadEnvFile_EmptyKeyto cover theos.Setenverror path inLoadEnvFileThe new test exercises the branch triggered when an env file contains a line with an empty key (e.g.
=somevalue). In that casestrings.SplitNproduces["", "somevalue"],keybecomes"", andos.Setenv("", ...)returnsinvalid argumenton Linux. The function wraps this as"failed to set ..."and returns the error — a path that was previously not exercised by any test.envfile.go95.7% / package 99.2%envfile.go100% / package 100%Test Execution
All tests pass:
Why These Changes?
LoadEnvFilecontains an explicit error-return branch foros.Setenvfailures, but no test triggered it. A line starting with=(empty key) reliably causesos.Setenv("", value)to fail withinvalid argument, making it the simplest and most direct way to exercise that branch. The change is a single focused test with no side effects on the rest of the environment (noSetenvsucceeds, so no cleanup is needed).Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests