test: add units tests for untested functions in style, api, types, and create packages#427
test: add units tests for untested functions in style, api, types, and create packages#427
Conversation
Add tests for untested functions across style, api, shared/types, and pkg/create packages to increase overall coverage from 70.1% to 70.6%.
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
mwbrooks
left a comment
There was a problem hiding this comment.
Comments for the kind ones out there! 🙇🏻
| 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()) | ||
| } | ||
|
|
There was a problem hiding this comment.
note: It makes me feel good to see these have some tests added.
| rawJSON: func() RawJSON { | ||
| raw := json.RawMessage(`{"name":"foo"}`) | ||
| return RawJSON{JSONData: &raw} | ||
| }(), |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
| 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) | ||
| }) | ||
| } |
There was a problem hiding this comment.
note: A bit scary how we change the os.Args[0] but I feel okay with the defer func() to reset it.
| expected: func() string { | ||
| if isWindows { | ||
| return homeDir + "/Documents/project" | ||
| } | ||
| return "~/Documents/project" | ||
| }(), |
There was a problem hiding this comment.
note: Again, I thought this was a nice way to return a string for the one test case that needs a bit of logic.
Changelog
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 stylethat I'm trying to leave alone while we have thehuhandlipglossexperiments.While not hugely impactful, this should increase our test coverage by about +0.5%.
Requirements