40 lines
925 B
Go
40 lines
925 B
Go
package shared
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/cli/cli/v2/pkg/cmdutil"
|
|
"github.com/cli/cli/v2/pkg/extensions"
|
|
"github.com/spf13/cobra"
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestExistingCommandFunc(t *testing.T) {
|
|
// Create fake command factory for testing.
|
|
factory := &cmdutil.Factory{
|
|
ExtensionManager: &extensions.ExtensionManagerMock{
|
|
ListFunc: func() []extensions.Extension {
|
|
return []extensions.Extension{}
|
|
},
|
|
},
|
|
}
|
|
|
|
// Create fake command structure for testing.
|
|
issueCmd := &cobra.Command{Use: "issue"}
|
|
prCmd := &cobra.Command{Use: "pr"}
|
|
prCmd.AddCommand(&cobra.Command{Use: "checkout"})
|
|
|
|
cmd := &cobra.Command{}
|
|
cmd.AddCommand(prCmd)
|
|
cmd.AddCommand(issueCmd)
|
|
|
|
f := ExistingCommandFunc(factory, cmd)
|
|
|
|
assert.True(t, f("pr"))
|
|
assert.True(t, f("pr checkout"))
|
|
assert.True(t, f("issue"))
|
|
|
|
assert.False(t, f("ps"))
|
|
assert.False(t, f("checkout"))
|
|
assert.False(t, f("repo list"))
|
|
}
|