chore: add various tests
This commit is contained in:
22
pkg/formatters/duration_test.go
Normal file
22
pkg/formatters/duration_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package formatters
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFormatDuration(t *testing.T) {
|
||||
tests := []struct {
|
||||
dur time.Duration
|
||||
want string
|
||||
}{
|
||||
{0, "N/A"},
|
||||
{22*24*time.Hour + 7*time.Hour + 39*time.Minute + 31*time.Second, "22d 7h 39m 31s"},
|
||||
{5*time.Minute + 15*time.Second, "5m 15s"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
if got := FormatDuration(tc.dur); got != tc.want {
|
||||
t.Errorf("FormatDuration(%v) = %s, want %s", tc.dur, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
22
pkg/formatters/numbers_test.go
Normal file
22
pkg/formatters/numbers_test.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package formatters
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFormatNumber(t *testing.T) {
|
||||
tests := []struct {
|
||||
input int64
|
||||
want string
|
||||
}{
|
||||
{0, "0"},
|
||||
{19823, "19.8k"},
|
||||
{1500000, "1.50M"},
|
||||
{-12345, "-12.3k"},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
if got := FormatNumber(tc.input); got != tc.want {
|
||||
t.Errorf("FormatNumber(%d) = %s, want %s", tc.input, got, tc.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user