spud/cli/start_service_test.go
Marc Cataford 17221855cc
Some checks failed
/ build (push) Has been cancelled
feat: add explicit flag / arg definitions
2024-09-28 21:49:46 -04:00

37 lines
743 B
Go

package cli
import (
"github.com/spf13/cobra"
"testing"
)
func TestCliStartServiceDefinitionPathMustExist(t *testing.T) {
cli := GetCli()
cli.SetArgs([]string{"start", "-d", "./not-a-file.yml"})
outcome := cli.Execute()
if outcome == nil {
t.Errorf("Expected error, got nil.")
}
}
func TestCliStartDefaultsServiceDefinitionPath(t *testing.T) {
cli := GetCli()
cli.SetArgs([]string{"start"})
startCommand, _, _ := cli.Find([]string{"start"})
startCommand.RunE = func(cmd *cobra.Command, args []string) error {
actual, _ := cmd.PersistentFlags().GetString("definition")
if actual != "./service.yml" {
t.Errorf("Unexpected default value for 'definition' / 'd' arg: %s", actual)
}
return nil
}
cli.Execute()
}