diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/console/console_test.go index c9f2d77b9bea..6692101c2b45 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/console/console_test.go @@ -18,7 +18,9 @@ package console import ( "bytes" + "fmt" "os" + "strconv" "testing" "golang.org/x/text/language" @@ -48,49 +50,40 @@ func (f *fakeFile) String() string { func TestOutStyle(t *testing.T) { var tests = []struct { - style string - envValue string - message string - params []interface{} - want string + style string + message string + params []interface{} + want string + wantASCII string }{ - {"happy", "true", "This is happy.", nil, "๐Ÿ˜„ This is happy.\n"}, - {"Docker", "true", "This is Docker.", nil, "๐Ÿณ This is Docker.\n"}, - {"option", "true", "This is option.", nil, " โ–ช This is option.\n"}, - { - "option", - "true", - "Message with params: %s %s", - []interface{}{"encode '%' signs", "%s%%%d"}, - " โ–ช Message with params: encode '%' signs %s%%%d\n", - }, - - {"happy", "false", "This is happy.", nil, "o This is happy.\n"}, - {"Docker", "false", "This is Docker.", nil, "- This is Docker.\n"}, - {"option", "false", "This is option.", nil, " - This is option.\n"}, - { - "option", - "false", - "Message with params: %s %s", - []interface{}{"encode '%' signs", "%s%%%d"}, - " - Message with params: encode '%' signs %s%%%d\n", - }, - {"issue", "true", "No separators for long ints: %d", []interface{}{10000}, " โ–ช No separators for long ints: 10000\n"}, - {"issue", "false", "No separators for long ints: %d", []interface{}{5000}, " - No separators for long ints: 5000\n"}, + {"happy", "Happy", nil, "๐Ÿ˜„ Happy\n", "* Happy\n"}, + {"option", "Option", nil, " โ–ช Option\n", " - Option\n"}, + {"warning", "Warning", nil, "โš ๏ธ Warning\n", "! Warning\n"}, + {"fatal", "Fatal: %v", []interface{}{"ugh"}, "๐Ÿ’ฃ Fatal: ugh\n", "X Fatal: ugh\n"}, + {"waiting-pods", "wait", nil, "โŒ› wait", "* wait"}, + {"issue", "http://i/%d", []interface{}{10000}, " โ–ช http://i/10000\n", " - http://i/10000\n"}, + {"usage", "raw: %s %s", []interface{}{"'%'", "%d"}, "๐Ÿ’ก raw: '%' %d\n", "* raw: '%' %d\n"}, } for _, tc := range tests { - t.Run(tc.style+"-"+tc.envValue, func(t *testing.T) { - os.Setenv(OverrideEnv, tc.envValue) - f := newFakeFile() - SetOutFile(f) - if err := OutStyle(tc.style, tc.message, tc.params...); err != nil { - t.Errorf("unexpected error: %q", err) - } - got := f.String() - if got != tc.want { - t.Errorf("OutStyle() = %q, want %q", got, tc.want) - } - }) + for _, override := range []bool{true, false} { + t.Run(fmt.Sprintf("%s-override-%v", tc.style, override), func(t *testing.T) { + // Set MINIKUBE_IN_STYLE= + os.Setenv(OverrideEnv, strconv.FormatBool(override)) + f := newFakeFile() + SetOutFile(f) + if err := OutStyle(tc.style, tc.message, tc.params...); err != nil { + t.Errorf("unexpected error: %q", err) + } + got := f.String() + want := tc.wantASCII + if override { + want = tc.want + } + if got != want { + t.Errorf("OutStyle() = %q (%d runes), want %q (%d runes)", got, len(got), want, len(want)) + } + }) + } } } diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index 453a90d0277d..022dadb580f9 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -25,8 +25,14 @@ import ( ) var ( - defaultLowPrefix = "- " - defautlLowIndentPrefix = " - " + // lowBullet is a bullet-point prefix for low-fi mode + lowBullet = "* " + // lowBullet is an indented bullet-point prefix for low-fi mode + lowIndent = " - " + // lowBullet is a warning prefix for low-fi mode + lowWarning = "! " + // lowBullet is an error prefix for low-fi mode + lowError = "X " ) // style describes how to stylize a message. @@ -42,47 +48,47 @@ type style struct { // styles is a map of style name to style struct // For consistency, ensure that emojis added render with the same width across platforms. var styles = map[string]style{ - "happy": {Prefix: "๐Ÿ˜„ ", LowPrefix: "o "}, + "happy": {Prefix: "๐Ÿ˜„ "}, "success": {Prefix: "โœ… "}, - "failure": {Prefix: "โŒ ", LowPrefix: "X "}, - "conflict": {Prefix: "๐Ÿ’ฅ ", LowPrefix: "x "}, - "fatal": {Prefix: "๐Ÿ’ฃ ", LowPrefix: "! "}, - "notice": {Prefix: "๐Ÿ“Œ ", LowPrefix: "* "}, - "ready": {Prefix: "๐Ÿ„ ", LowPrefix: "= "}, - "running": {Prefix: "๐Ÿƒ ", LowPrefix: ": "}, - "provisioning": {Prefix: "๐ŸŒฑ ", LowPrefix: "> "}, - "restarting": {Prefix: "๐Ÿ”„ ", LowPrefix: ": "}, - "reconfiguring": {Prefix: "๐Ÿ“ฏ ", LowPrefix: ": "}, - "stopping": {Prefix: "โœ‹ ", LowPrefix: ": "}, + "failure": {Prefix: "โŒ "}, + "conflict": {Prefix: "๐Ÿ’ฅ ", LowPrefix: lowWarning}, + "fatal": {Prefix: "๐Ÿ’ฃ ", LowPrefix: lowError}, + "notice": {Prefix: "๐Ÿ“Œ "}, + "ready": {Prefix: "๐Ÿ„ "}, + "running": {Prefix: "๐Ÿƒ "}, + "provisioning": {Prefix: "๐ŸŒฑ "}, + "restarting": {Prefix: "๐Ÿ”„ "}, + "reconfiguring": {Prefix: "๐Ÿ“ฏ "}, + "stopping": {Prefix: "โœ‹ "}, "stopped": {Prefix: "๐Ÿ›‘ "}, - "warning": {Prefix: "โš ๏ธ ", LowPrefix: "! "}, - "waiting": {Prefix: "โŒ› ", LowPrefix: ": "}, - "waiting-pods": {Prefix: "โŒ› ", LowPrefix: ": ", OmitNewline: true}, + "warning": {Prefix: "โš ๏ธ ", LowPrefix: lowWarning}, + "waiting": {Prefix: "โŒ› "}, + "waiting-pods": {Prefix: "โŒ› ", OmitNewline: true}, "usage": {Prefix: "๐Ÿ’ก "}, "launch": {Prefix: "๐Ÿš€ "}, - "sad": {Prefix: "๐Ÿ˜ฟ ", LowPrefix: "* "}, + "sad": {Prefix: "๐Ÿ˜ฟ "}, "thumbs-up": {Prefix: "๐Ÿ‘ "}, - "option": {Prefix: " โ–ช "}, // Indented bullet - "command": {Prefix: " โ–ช "}, // Indented bullet - "log-entry": {Prefix: " "}, // Indent + "option": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet + "command": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet + "log-entry": {Prefix: " "}, // Indent "crushed": {Prefix: "๐Ÿ’” "}, - "url": {Prefix: "๐Ÿ‘‰ "}, + "url": {Prefix: "๐Ÿ‘‰ ", LowPrefix: lowIndent}, "documentation": {Prefix: "๐Ÿ“˜ "}, "issues": {Prefix: "โ‰๏ธ "}, - "issue": {Prefix: " โ–ช "}, // Indented bullet + "issue": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet "check": {Prefix: "โœ”๏ธ "}, // Specialized purpose styles - "iso-download": {Prefix: "๐Ÿ’ฟ ", LowPrefix: "@ "}, - "file-download": {Prefix: "๐Ÿ’พ ", LowPrefix: "@ "}, - "caching": {Prefix: "๐Ÿคน ", LowPrefix: "$ "}, - "starting-vm": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "> "}, - "starting-none": {Prefix: "๐Ÿคน ", LowPrefix: "> "}, - "resetting": {Prefix: "๐Ÿ”„ ", LowPrefix: "# "}, - "deleting-host": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "x "}, + "iso-download": {Prefix: "๐Ÿ’ฟ "}, + "file-download": {Prefix: "๐Ÿ’พ "}, + "caching": {Prefix: "๐Ÿคน "}, + "starting-vm": {Prefix: "๐Ÿ”ฅ "}, + "starting-none": {Prefix: "๐Ÿคน "}, + "resetting": {Prefix: "๐Ÿ”„ "}, + "deleting-host": {Prefix: "๐Ÿ”ฅ "}, "copying": {Prefix: "โœจ "}, "connectivity": {Prefix: "๐Ÿ“ถ "}, - "internet": {Prefix: "๐ŸŒ ", LowPrefix: "o "}, + "internet": {Prefix: "๐ŸŒ "}, "mounting": {Prefix: "๐Ÿ“ "}, "celebrate": {Prefix: "๐ŸŽ‰ "}, "container-runtime": {Prefix: "๐ŸŽ "}, @@ -95,13 +101,13 @@ var styles = map[string]style{ "pulling": {Prefix: "๐Ÿšœ "}, "verifying": {Prefix: "๐Ÿค” "}, "verifying-noline": {Prefix: "๐Ÿค” ", OmitNewline: true}, - "kubectl": {Prefix: "๐Ÿ’— ", LowPrefix: "+ "}, - "meh": {Prefix: "๐Ÿ™„ ", LowPrefix: "? "}, - "embarrassed": {Prefix: "๐Ÿคฆ ", LowPrefix: "* "}, - "tip": {Prefix: "๐Ÿ’ก ", LowPrefix: "i "}, - "unmount": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "x "}, - "mount-options": {Prefix: "๐Ÿ’พ ", LowPrefix: "o "}, - "fileserver": {Prefix: "๐Ÿš€ ", LowPrefix: "@ ", OmitNewline: true}, + "kubectl": {Prefix: "๐Ÿ’— "}, + "meh": {Prefix: "๐Ÿ™„ ", LowPrefix: lowWarning}, + "embarrassed": {Prefix: "๐Ÿคฆ ", LowPrefix: lowWarning}, + "tip": {Prefix: "๐Ÿ’ก "}, + "unmount": {Prefix: "๐Ÿ”ฅ "}, + "mount-options": {Prefix: "๐Ÿ’พ "}, + "fileserver": {Prefix: "๐Ÿš€ ", OmitNewline: true}, } // Add a prefix to a string @@ -124,9 +130,9 @@ func lowPrefix(s style) string { return s.LowPrefix } if strings.HasPrefix(s.Prefix, " ") { - return defautlLowIndentPrefix + return lowIndent } - return defaultLowPrefix + return lowBullet } // Apply styling to a format string