diff --git a/cmd/minikube/cmd/config/addons_list.go b/cmd/minikube/cmd/config/addons_list.go index ddc207ae08ee..3a3b50ac0572 100644 --- a/cmd/minikube/cmd/config/addons_list.go +++ b/cmd/minikube/cmd/config/addons_list.go @@ -52,7 +52,11 @@ var addonsListCmd = &cobra.Command{ } func init() { - addonsListCmd.Flags().StringVar(&addonListFormat, "format", defaultAddonListFormat, + addonsListCmd.Flags().StringVarP( + &addonListFormat, + "format", + "f", + defaultAddonListFormat, `Go template format string for the addon list output. The format for Go templates can be found here: https://golang.org/pkg/text/template/ For the list of accessible variables for the template, see the struct values here: https://godoc.org/k8s.io/minikube/cmd/minikube/cmd/config#AddonListTemplate`) AddonsCmd.AddCommand(addonsListCmd) diff --git a/test/integration/functional_test.go b/test/integration/functional_test.go index 69a8864e93b7..7db6a9941169 100644 --- a/test/integration/functional_test.go +++ b/test/integration/functional_test.go @@ -29,6 +29,7 @@ import ( "os" "os/exec" "path/filepath" + "regexp" "strings" "testing" "time" @@ -87,6 +88,7 @@ func TestFunctional(t *testing.T) { {"MountCmd", validateMountCmd}, {"ProfileCmd", validateProfileCmd}, {"ServicesCmd", validateServicesCmd}, + {"AddonsCmd", validateAddonsCmd}, {"PersistentVolumeClaim", validatePersistentVolumeClaim}, {"TunnelCmd", validateTunnelCmd}, {"SSHCmd", validateSSHCmd}, @@ -314,6 +316,52 @@ func validateServicesCmd(ctx context.Context, t *testing.T, profile string) { } } +// validateAddonsCmd asserts basic "addon" command functionality +func validateAddonsCmd(ctx context.Context, t *testing.T, profile string) { + + // Default output + rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list")) + if err != nil { + t.Errorf("%s failed: %v", rr.Args, err) + } + listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n") + r := regexp.MustCompile(`-\s[a-z|-]+:\s(enabled|disabled)`) + for _, line := range listLines { + match := r.MatchString(line) + if !match { + t.Errorf("Plugin output did not match expected format. Got: %s", line) + } + } + + // Custom format + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list", "--format", `"{{.AddonName}}":"{{.AddonStatus}}"`)) + if err != nil { + t.Errorf("%s failed: %v", rr.Args, err) + } + listLines = strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n") + r = regexp.MustCompile(`"[a-z|-]+":"(enabled|disabled)"`) + for _, line := range listLines { + match := r.MatchString(line) + if !match { + t.Errorf("Plugin output did not match expected custom format. Got: %s", line) + } + } + + // Custom format shorthand + rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list", "-f", `"{{.AddonName}}":"{{.AddonStatus}}"`)) + if err != nil { + t.Errorf("%s failed: %v", rr.Args, err) + } + listLines = strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n") + r = regexp.MustCompile(`"[a-z|-]+":"(enabled|disabled)"`) + for _, line := range listLines { + match := r.MatchString(line) + if !match { + t.Errorf("Plugin output did not match expected custom format. Got: %s", line) + } + } +} + // validateSSHCmd asserts basic "ssh" command functionality func validateSSHCmd(ctx context.Context, t *testing.T, profile string) { if NoneDriver() {