2019-05-01 15:36:58 -05:00
|
|
|
package cmd_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-07-11 08:29:15 -05:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
|
2019-06-25 16:31:11 -05:00
|
|
|
"opendev.org/airship/airshipctl/cmd"
|
2019-07-11 08:29:15 -05:00
|
|
|
"opendev.org/airship/airshipctl/cmd/bootstrap"
|
|
|
|
"opendev.org/airship/airshipctl/pkg/environment"
|
|
|
|
"opendev.org/airship/airshipctl/testutil"
|
2019-05-01 15:36:58 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRoot(t *testing.T) {
|
2019-07-11 08:29:15 -05:00
|
|
|
tests := []*testutil.CmdTest{
|
2019-05-30 10:02:54 -05:00
|
|
|
{
|
2019-07-11 08:29:15 -05:00
|
|
|
Name: "rootCmd-with-no-defaults",
|
2019-05-29 15:11:55 -05:00
|
|
|
CmdLine: "",
|
2019-07-11 08:29:15 -05:00
|
|
|
Cmd: getVanillaRootCmd(t),
|
2019-05-29 15:11:55 -05:00
|
|
|
},
|
2019-07-11 08:29:15 -05:00
|
|
|
{
|
|
|
|
Name: "rootCmd-with-defaults",
|
|
|
|
CmdLine: "",
|
|
|
|
Cmd: getDefaultRootCmd(t),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "specialized-rootCmd-with-bootstrap",
|
|
|
|
CmdLine: "",
|
|
|
|
Cmd: getSpecializedRootCmd(t),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
testutil.RunTest(t, tt)
|
2019-05-24 08:47:49 -05:00
|
|
|
}
|
2019-07-11 08:29:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func getVanillaRootCmd(t *testing.T) *cobra.Command {
|
2019-05-29 15:11:55 -05:00
|
|
|
rootCmd, _, err := cmd.NewRootCmd(nil)
|
2019-05-24 15:38:59 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not create root command: %s", err.Error())
|
2019-05-24 08:47:49 -05:00
|
|
|
}
|
2019-07-11 08:29:15 -05:00
|
|
|
return rootCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func getDefaultRootCmd(t *testing.T) *cobra.Command {
|
|
|
|
rootCmd, _, err := cmd.NewAirshipCTLCommand(nil)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Could not create root command: %s", err.Error())
|
2019-05-29 15:11:55 -05:00
|
|
|
}
|
2019-07-11 08:29:15 -05:00
|
|
|
return rootCmd
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSpecializedRootCmd(t *testing.T) *cobra.Command {
|
|
|
|
rootCmd := getVanillaRootCmd(t)
|
|
|
|
rootCmd.AddCommand(bootstrap.NewBootstrapCommand(&environment.AirshipCTLSettings{}))
|
|
|
|
return rootCmd
|
2019-05-01 15:36:58 -05:00
|
|
|
}
|