Skip to content

Commit

Permalink
Add tests for addons custom output format
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Woodcock committed Oct 11, 2019
1 parent fdf5345 commit f39ecda
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cmd/minikube/cmd/config/addons_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
48 changes: 48 additions & 0 deletions test/integration/functional_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -87,6 +88,7 @@ func TestFunctional(t *testing.T) {
{"MountCmd", validateMountCmd},
{"ProfileCmd", validateProfileCmd},
{"ServicesCmd", validateServicesCmd},
{"AddonsCmd", validateAddonsCmd},
{"PersistentVolumeClaim", validatePersistentVolumeClaim},
{"TunnelCmd", validateTunnelCmd},
{"SSHCmd", validateSSHCmd},
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit f39ecda

Please sign in to comment.