2024-09-29 01:47:48 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import (
|
2024-10-05 00:28:09 +00:00
|
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
2024-09-29 01:47:48 +00:00
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-10-05 00:28:09 +00:00
|
|
|
func Test_StopServiceCli_StopRequiresAServiceName(t *testing.T) {
|
2024-09-29 01:47:48 +00:00
|
|
|
cli := GetCli()
|
|
|
|
|
|
|
|
cli.SetArgs([]string{"stop"})
|
|
|
|
|
|
|
|
outcome := cli.Execute()
|
|
|
|
|
|
|
|
if outcome == nil {
|
|
|
|
t.Error("Expected error, got nil.")
|
|
|
|
}
|
|
|
|
}
|
2024-10-05 00:28:09 +00:00
|
|
|
|
|
|
|
func Test_StopServiceCli_ErrorIfHostAndPortNotProvidedTogether(t *testing.T) {
|
|
|
|
inputs := [][]string{
|
|
|
|
{"stop", "-H", "host"},
|
|
|
|
{"stop", "-p", "9999"},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, input := range inputs {
|
|
|
|
t.Run(fmt.Sprintf("%+v", input), func(t *testing.T) {
|
|
|
|
cli := GetCli()
|
|
|
|
cli.SetArgs(input)
|
|
|
|
|
|
|
|
stopCommand, _, _ := cli.Find([]string{"stop"})
|
|
|
|
|
|
|
|
previousPreRun := stopCommand.PersistentPreRunE
|
|
|
|
|
|
|
|
stopCommand.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
|
|
|
if err := previousPreRun(cmd, args); err == nil {
|
|
|
|
t.Errorf("Expected error, got nil.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
stopCommand.RunE = func(cmd *cobra.Command, args []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.Execute()
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|