Skip to content

test: increase test coverage in cmd/ and internal/[api | config | deputil]#392

Merged
mwbrooks merged 6 commits intomainfrom
mwbrooks-test-coverage-simple-files
Mar 12, 2026
Merged

test: increase test coverage in cmd/ and internal/[api | config | deputil]#392
mwbrooks merged 6 commits intomainfrom
mwbrooks-test-coverage-simple-files

Conversation

@mwbrooks
Copy link
Member

@mwbrooks mwbrooks commented Mar 12, 2026

Changelog

  • N/A

Summary

This pull request increases our test coverage +0.8% by adding tests to untested functions in:

  • cmd/
  • internal/api
  • internal/config
  • internal/deputil

Requirements

@mwbrooks mwbrooks added this to the Next Release milestone Mar 12, 2026
@mwbrooks mwbrooks self-assigned this Mar 12, 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 12, 2026
@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.85%. Comparing base (4d5f768) to head (c4dbb36).
⚠️ Report is 2 commits behind head on main.

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

Consolidate GetAppStatus and ConnectionsOpen tests from separate
ok/error functions into table-driven tests using the map pattern.
Comment on lines +49 to +62
// 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)
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: 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.

@mwbrooks mwbrooks marked this pull request as ready for review March 12, 2026 04:34
@mwbrooks mwbrooks requested a review from a team as a code owner March 12, 2026 04:34
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

@mwbrooks Things gets better every day with changes like this. Thanks so much 🔋 ✨

I'm leaving not important thoughts and a few comments related, but please feel free to merge this whenever.

Comment on lines +495 to +519
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)
}
})
}
}
Copy link
Member

Choose a reason for hiding this comment

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

💡 thought: Unit tests matching each function is a kind pattern since IMHO it also encourages tests at the cmd level is preferred?

Copy link
Member Author

Choose a reason for hiding this comment

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

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!

}
}

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

Choose a reason for hiding this comment

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

🧮 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!

Copy link
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

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

Copy link
Member

Choose a reason for hiding this comment

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

⭐ praise: More praises for API tests! These are so good!

Comment on lines +50 to +54
flagNames := []string{
"apihost", "app", "config-dir", "experiment",
"force", "no-color", "skip-update", "slackdev",
"runtime", "team", "token", "verbose",
}
Copy link
Member

Choose a reason for hiding this comment

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

🧮 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!

Copy link
Member Author

Choose a reason for hiding this comment

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

@zimeg Great suggestion, I think a list with explicit variables for short and hidden make these tests more readable. Commit c4dbb36

Copy link
Member

Choose a reason for hiding this comment

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

📠 thought: A slackhttp package might be easier to find this ongoing? TIL about these modules too-

Copy link
Member Author

Choose a reason for hiding this comment

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

🧠 Makes sense that we can merge these two eventually! I'll add a note.

@mwbrooks
Copy link
Member Author

@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 → AppName() and SetAppName()). 🚀 rockets away, onto the next PR!

@mwbrooks mwbrooks merged commit 8e4c0aa into main Mar 12, 2026
8 checks passed
@mwbrooks mwbrooks deleted the mwbrooks-test-coverage-simple-files branch March 12, 2026 19:29
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.

2 participants