Add more tests, refactor to fix problems
Signed-off-by: Patrice Ferlet <metal3d@gmail.com>
This commit is contained in:
@@ -22,7 +22,11 @@ Each [command] and subcommand has got an "help" and "--help" flag to show more i
|
||||
`
|
||||
|
||||
func main() {
|
||||
// The base command
|
||||
rootCmd := buildRootCmd()
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func buildRootCmd() *cobra.Command {
|
||||
rootCmd := &cobra.Command{
|
||||
Use: "katenary",
|
||||
Long: longHelp,
|
||||
@@ -42,7 +46,7 @@ func main() {
|
||||
generateLabelHelpCommand(),
|
||||
)
|
||||
|
||||
rootCmd.Execute()
|
||||
return rootCmd
|
||||
}
|
||||
|
||||
const completionHelp = `To load completions:
|
||||
|
17
cmd/katenary/main_test.go
Normal file
17
cmd/katenary/main_test.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestBuildCommand(t *testing.T) {
|
||||
rootCmd := buildRootCmd()
|
||||
if rootCmd == nil {
|
||||
t.Errorf("Expected rootCmd to be defined")
|
||||
}
|
||||
if rootCmd.Use != "katenary" {
|
||||
t.Errorf("Expected rootCmd.Use to be katenary, got %s", rootCmd.Use)
|
||||
}
|
||||
numCommands := 5
|
||||
if len(rootCmd.Commands()) != numCommands {
|
||||
t.Errorf("Expected %d command, got %d", numCommands, len(rootCmd.Commands()))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user