-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Description
When I test Cobra command, I do this:
cmd := NewCmdStatus(cmdutils.NewFactory())
t.Run("no repo", func(t *testing.T) {
err := cmd.Execute()
assert.Error(t, err)
})
t.Run("no repo with -R", func(t *testing.T) {
cmd.SetArgs([]string{"-R", "forkrepo"})
err := cmd.Execute()
assert.NoError(t, err)
})
The problem is that -R
is defined in parent command, so the test fails.
I tried to add the flag explicitly to NewCmdStatus
, but that didn't work too.
cmd.InheritedFlags().StringP("repo", "R", "", "Select another repository.")
So how to test that?
Metadata
Metadata
Assignees
Labels
No labels