spud/cli/build_test.go

38 lines
743 B
Go
Raw Normal View History

package cli
import (
"github.com/spf13/cobra"
"testing"
)
func TestCliBuildServiceDefinitionPathMustExist(t *testing.T) {
cli := GetCli()
cli.SetArgs([]string{"build", "-d", "./not-a-file.yml"})
outcome := cli.Execute()
if outcome == nil {
t.Errorf("Expected error, got nil.")
}
}
func TestCliBuildDefaultsServiceDefinitionPath(t *testing.T) {
cli := GetCli()
cli.SetArgs([]string{"build"})
startCommand, _, _ := cli.Find([]string{"build"})
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()
}