test: increase test coverage in cmd/ and internal/[api | config | deputil]#392
test: increase test coverage in cmd/ and internal/[api | config | deputil]#392
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #392 +/- ##
==========================================
+ Coverage 67.01% 67.85% +0.84%
==========================================
Files 218 218
Lines 18090 18090
==========================================
+ Hits 12123 12275 +152
+ Misses 4833 4656 -177
- Partials 1134 1159 +25 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Consolidate GetAppStatus and ConnectionsOpen tests from separate ok/error functions into table-driven tests using the map pattern.
internal/config/flags_test.go
Outdated
| // Verify that key persistent flags were registered | ||
| flagNames := []string{ | ||
| "apihost", "app", "config-dir", "experiment", | ||
| "force", "no-color", "skip-update", "slackdev", | ||
| "runtime", "team", "token", "verbose", | ||
| } | ||
| for _, name := range flagNames { | ||
| f := cmd.PersistentFlags().Lookup(name) | ||
| assert.NotNil(t, f, "flag %s should be registered", name) | ||
| } | ||
|
|
||
| // Verify hidden flags | ||
| assert.True(t, cmd.PersistentFlags().Lookup("apihost").Hidden) | ||
| assert.True(t, cmd.PersistentFlags().Lookup("slackdev").Hidden) |
There was a problem hiding this comment.
note: I went back-and-forth on whether to have this test, but it's nice to have a test that locks-in and confirms that our expected global flags and hidden flags haven't changed without intention.
| func Test_mapAttributeFlag(t *testing.T) { | ||
| tests := map[string]struct { | ||
| flag string | ||
| wantErr bool | ||
| }{ | ||
| "valid JSON": { | ||
| flag: `{"#name":"name"}`, | ||
| }, | ||
| "invalid JSON": { | ||
| flag: `not json`, | ||
| wantErr: true, | ||
| }, | ||
| } | ||
| for name, tc := range tests { | ||
| t.Run(name, func(t *testing.T) { | ||
| result, err := mapAttributeFlag(tc.flag) | ||
| if tc.wantErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| assert.NoError(t, err) | ||
| assert.NotNil(t, result) | ||
| } | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
💡 thought: Unit tests matching each function is a kind pattern since IMHO it also encourages tests at the cmd level is preferred?
There was a problem hiding this comment.
I agree, I think we could actually reduce our overall tests and have the same coverage by testing through the command level. We've had success with some of the simpler, newer commands and hopefully we can bring that to the original, complex commands!
internal/api/app_test.go
Outdated
| } | ||
| } | ||
|
|
||
| func Test_Client_ConnectionsOpen(t *testing.T) { |
There was a problem hiding this comment.
🧮 quibble(non-blocking): Forgive me for not searching too much up, but if tests have alphabetical order in this file?
👾 ramble: I'd be curious if separating API methods into different files gives us the most confidence toward focused tests. Not something to change now of course, but it'd be curious pattern for ongoing additions!
There was a problem hiding this comment.
Unfortunately, it's not alphabetized. The file looks like it started off being alphabetical, but after line 200, it's a free-for-all. Commit e2e0ed5 attempts to move these functions where they should be.
A challenge with alphabetizing is that logically we want to group getters/setters but alphabetically they are separated. Something for us to think about.
There was a problem hiding this comment.
👾 ramble: I'd be curious if separating API methods into different files gives us the most confidence toward focused tests. Not something to change now of course, but it'd be curious pattern for ongoing additions!
Personally, I prefer small files would be open to a single file for each API method. But Golang tends to prefer fewer, longer files. That's probably why we are taking the current approach.
There was a problem hiding this comment.
⭐ praise: More praises for API tests! These are so good!
internal/config/flags_test.go
Outdated
| flagNames := []string{ | ||
| "apihost", "app", "config-dir", "experiment", | ||
| "force", "no-color", "skip-update", "slackdev", | ||
| "runtime", "team", "token", "verbose", | ||
| } |
There was a problem hiding this comment.
🧮 quibble: Separating these to newlines might be nice for fast reading. I assumed this was a map at first! Perhaps this can be a table test?
tests := map[string]struct{
shorthand string
longform string
}{
"apihost": {
longform: "apihost",
},
"app": {
longform: "app",
shortform: "a",
},
}IIRC? Forgive me if shortform is too much. I'm hopeful that we'll soon revisit some of these options like app and team too!
There was a problem hiding this comment.
📠 thought: A slackhttp package might be easier to find this ongoing? TIL about these modules too-
There was a problem hiding this comment.
🧠 Makes sense that we can merge these two eventually! I'll add a note.
|
@zimeg Thanks for the thorough review! I'll try to keep things alphabetized and maybe we can find a common standard for how to order getter/settings (e.g. Getters don't include "Get" and Setter always follows the Getter → |
Changelog
Summary
This pull request increases our test coverage +0.8% by adding tests to untested functions in:
cmd/internal/apiinternal/configinternal/deputilRequirements