diff --git a/main.go b/main.go index 491638c..6002b15 100644 --- a/main.go +++ b/main.go @@ -559,6 +559,9 @@ func humanizeDurationSeconds(seconds float64) string { for n := duration / unit; n >= unit; n /= unit { div *= unit exp++ + if exp >= len(units)-1 { + break + } } return fmt.Sprintf("%.2f%s", diff --git a/main_test.go b/main_test.go index 4da3c92..ab75e67 100644 --- a/main_test.go +++ b/main_test.go @@ -43,3 +43,20 @@ func TestHeadersParsing(t *testing.T) { } } } + +func TestHumanizeDurationSeconds(t *testing.T) { + requestTime := humanizeDurationSeconds(6000) + if requestTime != "6000.00s" { + t.Errorf("Wrong requestTime: %q", requestTime) + } + + requestTime = humanizeDurationSeconds(0.05) + if requestTime != "50.00ms" { + t.Errorf("Wrong requestTime: %q", requestTime) + } + + requestTime = humanizeDurationSeconds(99999999) + if requestTime != "99999999.00s" { + t.Errorf("Wrong requestTime: %q", requestTime) + } +}