Skip to content

test: add test coverage for untested files - #388

Merged
mwbrooks merged 12 commits into
mainfrom
mwbrooks-test-coverage-new-files
Mar 12, 2026
Merged

test: add test coverage for untested files#388
mwbrooks merged 12 commits into
mainfrom
mwbrooks-test-coverage-new-files

Conversation

@mwbrooks

@mwbrooksmwbrooks commented Mar 11, 2026

Copy link
Copy Markdown
Member

Changelog

  • N/A

Summary

This pull request add unit test coverage for 10 previously untested files across internal packages:

  • internal/api
  • internal/archiveutil
  • internal/cmdutil
  • internal/config
  • internal/goutils
  • internal/image
  • internal/iostreams
  • internal/ioutils
  • internal/prompts

Only test files were changed in this pull request.

Requirements

@mwbrooksmwbrooks added this to the Next Release milestone Mar 11, 2026
@mwbrooksmwbrooks self-assigned this Mar 11, 2026
@mwbrooksmwbrooks added code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment labels Mar 11, 2026
@codecov

codecovBot commented Mar 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.96%. Comparing base (23baa9e) to head (26d5fbb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #388 +/- ##
==========================================
+ Coverage 65.48% 66.96% +1.47% 
==========================================
Files 218 218 Lines 18090 18090 ==========================================
+ Hits 11847 12114 +267 + Misses 5154 4839 -315 - Partials 1089 1137 +48 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mwbrooksmwbrooks left a comment

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Comments the kind ones 🤾🏻

Comment on lines +30 to +31
// TODO: Refactor to use afero.Fs once ExtractAndWriteFile accepts it. Currently uses t.TempDir() which is safe.
func Test_ExtractAndWriteFile(t *testing.T) {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

note: I've decided to implement these tests now using the t.TempDir() approach, but I've added a comment to refactor the code being tested to inject afero.Fs so that we can change the tests to be our memory-base FS.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mwbrooks Amazing callout! Having these tests in place will make that change much more confident I think! 🧪 ✨

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

Happy to hear that you agree. I was on the fence, since we are trying to avoid I/O during testing. But I'll be sure to follow-up and remove these in an upcoming PR.

Comment on lines +86 to +87
// TODO: Refactor to use afero.Fs once Copy accepts it. Currently uses t.TempDir() which is safe.
func Test_Copy(t *testing.T) {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

note: More reminders to refactor this, but these tests are safe to run since they are in the temp directory (just slower).


// TODO: Refactor to use afero.Fs once CopyDirectory accepts it. Currently uses t.TempDir() which is safe.
func Test_CopyDirectory(t *testing.T) {
t.Run("copies directory structure", func(t *testing.T) {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

note: Not using Table Tests here because each test case needs unique setup. To find a balance, I'm using the t.Run("...") to still group the test cases together in the same spirit as table tests.

@mwbrooks
mwbrooks marked this pull request as ready for review March 11, 2026 20:41
@mwbrooks
mwbrooks requested a review from a team as a code ownerMarch 11, 2026 20:41

@srtaalejsrtaalej 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.

LGTM! thanks for increasing our coverage 🟢 🟢 🟢 🚀

@zimegzimeg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mwbrooks Another kind improvement to code health. This builds more and more confidence I feel! 🐢

Comment on lines +30 to +31
// TODO: Refactor to use afero.Fs once ExtractAndWriteFile accepts it. Currently uses t.TempDir() which is safe.
func Test_ExtractAndWriteFile(t *testing.T) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@mwbrooks Amazing callout! Having these tests in place will make that change much more confident I think! 🧪 ✨

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⭐ praise: These tests aren't so complicated but that's amazing I think! It gives me confidence that existing API methods are gathering expected responses as we expect!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

📸 note: TIL about this package!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🧪 thought: Increasing coverage is appreciated so much but I'm worried that it builds confidence in patterns we're wanting to move from. I don't think command specific prompts ought be separate from commands but let's not address that now!

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

thought: I think it's entirely okay to delete old, unrelated tests. So I hope it doesn't discourage future refactors.

Comment threadinternal/ioutils/host_test.go Outdated
Comment on lines +26 to +29
assert.NotEmpty(t, hostname)
// The hostname should be hashed, not the raw hostname
// It should not be "unknown" on a normal system
assert.NotEqual(t, "", hostname)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🗣️ question(non-blocking): Is not empty the same as not equal to empty string?

@mwbrooksmwbrooksMar 12, 2026

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@zimeg Good eye! This should have tested for assert.NotEqual(t, "unknown", hostname) 🙇🏻 Fixed in commit 758ce76

@mwbrooks

Copy link
Copy Markdown
MemberAuthor

@srtaalej@zimeg Thanks so much for the reviews and slogging through a shameful 1,000 line PR! At least this one moves the needle a little more on code cov 🧪

@mwbrooks
mwbrooks merged commit ca87f1d into mainMar 12, 2026
8 checks passed
@mwbrooks
mwbrooks deleted the mwbrooks-test-coverage-new-files branch March 12, 2026 02:33
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code healthM-T: Test improvements and anything that improves code healthsemver:patchUse on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@mwbrooks@zimeg@srtaalej