Add tests for addons custom output format
parent
fdf5345616
commit
f39ecda4cb
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue