Apply linter autofixes: internal/storage, types, ui (refs #61)
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
func newTestWriter(color bool) (*Writer, *bytes.Buffer) {
|
||||
buf := &bytes.Buffer{}
|
||||
|
||||
return NewWithColor(buf, color), buf
|
||||
}
|
||||
|
||||
@@ -33,6 +34,7 @@ func TestMessageMethodsPlain(t *testing.T) {
|
||||
t.Run(tt.method, func(t *testing.T) {
|
||||
w, buf := newTestWriter(false)
|
||||
tt.fn(w)
|
||||
|
||||
if got := buf.String(); got != tt.want {
|
||||
t.Errorf("got %q, want %q", got, tt.want)
|
||||
}
|
||||
@@ -45,13 +47,16 @@ func TestWarningErrorCounters(t *testing.T) {
|
||||
if w.WarningCount() != 0 || w.ErrorCount() != 0 {
|
||||
t.Fatalf("expected fresh writer to have zero counts")
|
||||
}
|
||||
|
||||
w.Info("normal")
|
||||
w.Warning("first warn")
|
||||
w.Warning("second warn")
|
||||
w.Error("only error")
|
||||
|
||||
if got, want := w.WarningCount(), 2; got != want {
|
||||
t.Errorf("WarningCount: got %d, want %d", got, want)
|
||||
}
|
||||
|
||||
if got, want := w.ErrorCount(), 1; got != want {
|
||||
t.Errorf("ErrorCount: got %d, want %d", got, want)
|
||||
}
|
||||
@@ -60,10 +65,12 @@ func TestWarningErrorCounters(t *testing.T) {
|
||||
func TestColorOutputContainsANSI(t *testing.T) {
|
||||
w, buf := newTestWriter(true)
|
||||
w.Error("boom")
|
||||
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "\033[") {
|
||||
t.Errorf("expected ANSI escapes in color output, got %q", out)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "ERROR: ") {
|
||||
t.Errorf("expected 'ERROR: ' text in output, got %q", out)
|
||||
}
|
||||
@@ -72,6 +79,7 @@ func TestColorOutputContainsANSI(t *testing.T) {
|
||||
func TestBannerBoldWhenColor(t *testing.T) {
|
||||
w, buf := newTestWriter(true)
|
||||
w.Banner("hello")
|
||||
|
||||
out := buf.String()
|
||||
if !strings.Contains(out, "\033[1m") {
|
||||
t.Errorf("expected bold ANSI escape in colored Banner output, got %q", out)
|
||||
@@ -84,18 +92,23 @@ func TestValueFormattersPlain(t *testing.T) {
|
||||
if got := w.Hex("0123456789abcdef0123"); got != "0123456789ab..." {
|
||||
t.Errorf("Hex long: got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Hex("short"); got != "short" {
|
||||
t.Errorf("Hex short: got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Size(1024); got != "1.0 kB" {
|
||||
t.Errorf("Size: got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Duration(90 * time.Second); got != "1m30s" {
|
||||
t.Errorf("Duration: got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Count(12345); got != "12,345" {
|
||||
t.Errorf("Count: got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Percent(12.34); got != "12.3%" {
|
||||
t.Errorf("Percent: got %q", got)
|
||||
}
|
||||
@@ -104,9 +117,11 @@ func TestValueFormattersPlain(t *testing.T) {
|
||||
if got := w.Speed(0); got != "N/A" {
|
||||
t.Errorf("Speed(0): got %q, want N/A", got)
|
||||
}
|
||||
|
||||
if got := w.Speed(125_000_000); got != "1.0 Gbit/sec" { // 1 Gbit/s = 125 MB/s
|
||||
t.Errorf("Speed(125e6): got %q", got)
|
||||
}
|
||||
|
||||
if got := w.Speed(125_000); got != "1 Mbit/sec" {
|
||||
t.Errorf("Speed(125e3): got %q", got)
|
||||
}
|
||||
@@ -116,6 +131,7 @@ func TestValueFormattersPlain(t *testing.T) {
|
||||
if got := w.Time(today); got != "14:30:45" {
|
||||
t.Errorf("Time today: got %q, want 14:30:45", got)
|
||||
}
|
||||
|
||||
other := time.Date(2030, 1, 2, 3, 4, 5, 0, time.Local)
|
||||
if got := w.Time(other); got != "2030-01-02 03:04:05" {
|
||||
t.Errorf("Time other day: got %q", got)
|
||||
@@ -124,10 +140,12 @@ func TestValueFormattersPlain(t *testing.T) {
|
||||
|
||||
func TestValueFormattersColored(t *testing.T) {
|
||||
w, _ := newTestWriter(true)
|
||||
|
||||
hex := w.Hex("0123456789abcdef0123")
|
||||
if !strings.Contains(hex, "\033[") {
|
||||
t.Errorf("expected ANSI in colored Hex output, got %q", hex)
|
||||
}
|
||||
|
||||
if !strings.Contains(hex, "0123456789ab") {
|
||||
t.Errorf("expected hex content in output, got %q", hex)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user