-
Notifications
You must be signed in to change notification settings - Fork 32
test: increase test coverage in cmd/ and internal/[api | config | deputil] #392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a155ba5
28f1bf2
58c9c3f
c2f5c7e
e2e0ed5
c4dbb36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ⭐ praise: More praises for API tests! These are so good! |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,44 @@ import ( | |
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestSetFlags(t *testing.T) { | ||
| fs := slackdeps.NewFsMock() | ||
| os := slackdeps.NewOsMock() | ||
| config := NewConfig(fs, os) | ||
| cmd := &cobra.Command{} | ||
| cmd.Flags().String("test-flag", "default", "a test flag") | ||
|
|
||
| config.SetFlags(cmd) | ||
| assert.NotNil(t, config.Flags) | ||
| f := config.Flags.Lookup("test-flag") | ||
| assert.NotNil(t, f) | ||
| assert.Equal(t, "default", f.DefValue) | ||
| } | ||
|
|
||
| func TestInitializeGlobalFlags(t *testing.T) { | ||
| fs := slackdeps.NewFsMock() | ||
| os := slackdeps.NewOsMock() | ||
| config := NewConfig(fs, os) | ||
| cmd := &cobra.Command{} | ||
|
|
||
| config.InitializeGlobalFlags(cmd) | ||
|
|
||
| // Verify that key persistent flags were registered | ||
| flagNames := []string{ | ||
| "apihost", "app", "config-dir", "experiment", | ||
| "force", "no-color", "skip-update", "slackdev", | ||
| "runtime", "team", "token", "verbose", | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| 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) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } | ||
|
|
||
| func TestDeprecatedFlagSubstitutions(t *testing.T) { | ||
| tests := map[string]struct { | ||
| expectedWarnings []string | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📠 thought: A
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
There was a problem hiding this comment.
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
cmdlevel is preferred?There was a problem hiding this comment.
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!