Skip to content

Commit f39ecda

Browse files
author
Josh Woodcock
committed
Add tests for addons custom output format
1 parent fdf5345 commit f39ecda

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

cmd/minikube/cmd/config/addons_list.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ var addonsListCmd = &cobra.Command{
5252
}
5353

5454
func init() {
55-
addonsListCmd.Flags().StringVar(&addonListFormat, "format", defaultAddonListFormat,
55+
addonsListCmd.Flags().StringVarP(
56+
&addonListFormat,
57+
"format",
58+
"f",
59+
defaultAddonListFormat,
5660
`Go template format string for the addon list output. The format for Go templates can be found here: https://golang.org/pkg/text/template/
5761
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`)
5862
AddonsCmd.AddCommand(addonsListCmd)

test/integration/functional_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"os"
3030
"os/exec"
3131
"path/filepath"
32+
"regexp"
3233
"strings"
3334
"testing"
3435
"time"
@@ -87,6 +88,7 @@ func TestFunctional(t *testing.T) {
8788
{"MountCmd", validateMountCmd},
8889
{"ProfileCmd", validateProfileCmd},
8990
{"ServicesCmd", validateServicesCmd},
91+
{"AddonsCmd", validateAddonsCmd},
9092
{"PersistentVolumeClaim", validatePersistentVolumeClaim},
9193
{"TunnelCmd", validateTunnelCmd},
9294
{"SSHCmd", validateSSHCmd},
@@ -314,6 +316,52 @@ func validateServicesCmd(ctx context.Context, t *testing.T, profile string) {
314316
}
315317
}
316318

319+
// validateAddonsCmd asserts basic "addon" command functionality
320+
func validateAddonsCmd(ctx context.Context, t *testing.T, profile string) {
321+
322+
// Default output
323+
rr, err := Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list"))
324+
if err != nil {
325+
t.Errorf("%s failed: %v", rr.Args, err)
326+
}
327+
listLines := strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
328+
r := regexp.MustCompile(`-\s[a-z|-]+:\s(enabled|disabled)`)
329+
for _, line := range listLines {
330+
match := r.MatchString(line)
331+
if !match {
332+
t.Errorf("Plugin output did not match expected format. Got: %s", line)
333+
}
334+
}
335+
336+
// Custom format
337+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list", "--format", `"{{.AddonName}}":"{{.AddonStatus}}"`))
338+
if err != nil {
339+
t.Errorf("%s failed: %v", rr.Args, err)
340+
}
341+
listLines = strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
342+
r = regexp.MustCompile(`"[a-z|-]+":"(enabled|disabled)"`)
343+
for _, line := range listLines {
344+
match := r.MatchString(line)
345+
if !match {
346+
t.Errorf("Plugin output did not match expected custom format. Got: %s", line)
347+
}
348+
}
349+
350+
// Custom format shorthand
351+
rr, err = Run(t, exec.CommandContext(ctx, Target(), "-p", profile, "addons", "list", "-f", `"{{.AddonName}}":"{{.AddonStatus}}"`))
352+
if err != nil {
353+
t.Errorf("%s failed: %v", rr.Args, err)
354+
}
355+
listLines = strings.Split(strings.TrimSpace(rr.Stdout.String()), "\n")
356+
r = regexp.MustCompile(`"[a-z|-]+":"(enabled|disabled)"`)
357+
for _, line := range listLines {
358+
match := r.MatchString(line)
359+
if !match {
360+
t.Errorf("Plugin output did not match expected custom format. Got: %s", line)
361+
}
362+
}
363+
}
364+
317365
// validateSSHCmd asserts basic "ssh" command functionality
318366
func validateSSHCmd(ctx context.Context, t *testing.T, profile string) {
319367
if NoneDriver() {

0 commit comments

Comments
 (0)