Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

52 lines
1.1 KiB
Go

package progress
import (
"testing"
"time"
)
func TestFormatElapsed(t *testing.T) {
cases := []struct {
d time.Duration
want string
}{
{0, "0s"},
{30 * time.Second, "30s"},
{90 * time.Second, "1m 30s"},
{3700 * time.Second, "1h 01m"},
}
for _, c := range cases {
if got := FormatElapsed(c.d); got != c.want {
t.Errorf("FormatElapsed(%v) = %q, want %q", c.d, got, c.want)
}
}
}
func TestETAAndStats(t *testing.T) {
start := time.Now().Add(-10 * time.Second)
rate, eta := ETA(start, 100, 200)
if rate < 5 || rate > 20 { // ~10/s
t.Errorf("rate = %v, want ~10/s", rate)
}
if eta <= 0 {
t.Error("eta should be positive when total > current")
}
// Unknown total → no eta.
if _, eta2 := ETA(start, 100, 0); eta2 != 0 {
t.Errorf("unknown total must yield zero eta, got %v", eta2)
}
ps := Stats(string(PhaseParse), start, 100, 200)
if ps.Percent != 50 {
t.Errorf("percent = %d, want 50", ps.Percent)
}
if ps.ETA == "" {
t.Error("Stats must include an ETA when total known")
}
if ps.Phase != "parsing" {
t.Errorf("phase = %q", ps.Phase)
}
}