Skip to content

test: add units tests for untested functions in style, api, types, and create packages#427

Open
mwbrooks wants to merge 1 commit intomainfrom
mwbrooks-test-coverage-easy-picking
Open

test: add units tests for untested functions in style, api, types, and create packages#427
mwbrooks wants to merge 1 commit intomainfrom
mwbrooks-test-coverage-easy-picking

Conversation

@mwbrooks
Copy link
Member

Changelog

  • N/A

Summary

This pull request is that last in my effort to add test coverage to our untested functions. The remaining, untested functions are part of package style that I'm trying to leave alone while we have the huh and lipgloss experiments.

While not hugely impactful, this should increase our test coverage by about +0.5%.

Requirements

Add tests for untested functions across style, api, shared/types, and
pkg/create packages to increase overall coverage from 70.1% to 70.6%.
@mwbrooks mwbrooks added this to the Next Release milestone Mar 20, 2026
@mwbrooks mwbrooks self-assigned this Mar 20, 2026
@mwbrooks mwbrooks 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 20, 2026
@codecov
Copy link

codecov bot commented Mar 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 70.24%. Comparing base (c20760d) to head (63a03c5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #427      +/-   ##
==========================================
+ Coverage   69.76%   70.24%   +0.48%     
==========================================
  Files         220      220              
  Lines       18446    18446              
==========================================
+ Hits        12869    12958      +89     
+ Misses       4407     4317      -90     
- Partials     1170     1171       +1     

☔ 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.

Copy link
Member Author

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

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

Comments for the kind ones out there! 🙇🏻

Comment on lines +26 to +43
func Test_Template_GetSubdir(t *testing.T) {
t.Run("default is empty string", func(t *testing.T) {
tmpl := Template{}
assert.Equal(t, "", tmpl.GetSubdir())
})
t.Run("returns value set by SetSubdir", func(t *testing.T) {
tmpl := Template{}
tmpl.SetSubdir("subpath")
assert.Equal(t, "subpath", tmpl.GetSubdir())
})
}

func Test_Template_SetSubdir(t *testing.T) {
tmpl := Template{}
tmpl.SetSubdir("custom/dir")
assert.Equal(t, "custom/dir", tmpl.GetSubdir())
}

Copy link
Member Author

Choose a reason for hiding this comment

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

note: It makes me feel good to see these have some tests added.

Comment on lines +57 to +60
rawJSON: func() RawJSON {
raw := json.RawMessage(`{"name":"foo"}`)
return RawJSON{JSONData: &raw}
}(),
Copy link
Member Author

Choose a reason for hiding this comment

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

note: TIL about an anonymous function as a way to populate a variable in our test tables. It's actually handy, although it can be difficult to read when overused.

"github.com/stretchr/testify/require"
)

func Test_SlackYaml_hasValidIconPath(t *testing.T) {
Copy link
Member Author

Choose a reason for hiding this comment

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

threat: I'm coming for you SlackYaml. Not today. Not tomorrow. But one day, I'm coming for you and giving you a new name.

Comment on lines +214 to +229
for name, tc := range tests {
t.Run(name, func(t *testing.T) {
processTemp := os.Args[0]
os.Args[0] = "slack"
globalColorShown := isColorShown
isColorShown = true
defer func() {
os.Args[0] = processTemp
isColorShown = globalColorShown
}()

formatted := Commandf(tc.command, tc.isPrimary)
assert.NotContains(t, formatted, "`")
assert.Contains(t, formatted, tc.command)
})
}
Copy link
Member Author

Choose a reason for hiding this comment

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

note: A bit scary how we change the os.Args[0] but I feel okay with the defer func() to reset it.

Comment on lines +341 to +346
expected: func() string {
if isWindows {
return homeDir + "/Documents/project"
}
return "~/Documents/project"
}(),
Copy link
Member Author

Choose a reason for hiding this comment

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

note: Again, I thought this was a nice way to return a string for the one test case that needs a bit of logic.

@mwbrooks mwbrooks marked this pull request as ready for review March 20, 2026 23:47
@mwbrooks mwbrooks requested a review from a team as a code owner March 20, 2026 23:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code health M-T: Test improvements and anything that improves code health semver:patch Use on pull requests to describe the release version increment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant