Skip to content

[test-improver] Improve tests for envutil package#6960

Merged
lpcox merged 1 commit into
mainfrom
test-improver/envutil-envfile-coverage-f6a433db5b41486e
Jun 4, 2026
Merged

[test-improver] Improve tests for envutil package#6960
lpcox merged 1 commit into
mainfrom
test-improver/envutil-envfile-coverage-f6a433db5b41486e

Conversation

@github-actions

@github-actions github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

File Analyzed

  • Test File: internal/envutil/envfile_test.go
  • Package: internal/envutil

Improvements Made

1. Increased Coverage

  • ✅ Added TestLoadEnvFile_EmptyKey to cover the os.Setenv error path in LoadEnvFile

The new test exercises the branch triggered when an env file contains a line with an empty key (e.g. =somevalue). In that case strings.SplitN produces ["", "somevalue"], key becomes "", and os.Setenv("", ...) returns invalid argument on Linux. The function wraps this as "failed to set ..." and returns the error — a path that was previously not exercised by any test.

  • Previous Coverage: envfile.go 95.7% / package 99.2%
  • New Coverage: envfile.go 100% / package 100%
  • Improvement: +4.3% (envfile.go), +0.8% (package)

Test Execution

All tests pass:

=== RUN   TestLoadEnvFile_EmptyKey
--- PASS: TestLoadEnvFile_EmptyKey (0.00s)
PASS
ok  github.com/github/gh-aw-mcpg/internal/envutil  coverage: 100.0% of statements

Why These Changes?

LoadEnvFile contains an explicit error-return branch for os.Setenv failures, but no test triggered it. A line starting with = (empty key) reliably causes os.Setenv("", value) to fail with invalid 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 (no Setenv succeeds, so no cleanup is needed).


Generated by Test Improver Workflow
Focuses on better patterns, increased coverage, and more stable tests

Generated by Test Improver · sonnet46 4.5M ·

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>
@lpcox lpcox marked this pull request as ready for review June 4, 2026 14:39
Copilot AI review requested due to automatic review settings June 4, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_EmptyKey to assert LoadEnvFile returns an error for a line like =somevalue.
  • Verified the returned error includes the wrapper message "failed to set" used by LoadEnvFile.
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

@lpcox lpcox merged commit 96251d3 into main Jun 4, 2026
23 checks passed
@lpcox lpcox deleted the test-improver/envutil-envfile-coverage-f6a433db5b41486e branch June 4, 2026 15:46
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