mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 18:34:46 +00:00
test: add formatUnusedTime tests and fix duplicate comment
Add unit tests for formatUnusedTime in cmd/analyze/format_test.go:
- Zero time (time.Time{}) returns empty string
- Recent files (< 90 days) return empty string
- Boundary tests at 89/90 days threshold
- Month formatting (3mo, 4mo, 6mo, 11mo, 12mo)
- Year formatting (1yr, 2yr, 3yr)
- Boundary tests at year transitions
Also remove duplicate "Memory pressure penalty" comment in
cmd/status/metrics_health.go (line 72-73).
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRuneWidth(t *testing.T) {
|
||||
@@ -307,3 +308,41 @@ func TestCalculateNameWidth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatUnusedTime(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
daysAgo int
|
||||
want string
|
||||
}{
|
||||
{"zero time", -1, ""}, // Special case: will use time.Time{}
|
||||
{"recent file", 30, ""}, // < 90 days returns empty
|
||||
{"just under threshold", 89, ""}, // Boundary: 89 days still empty
|
||||
{"at 90 days", 90, ">3mo"}, // Boundary: exactly 90 days
|
||||
{"4 months", 120, ">4mo"},
|
||||
{"6 months", 180, ">6mo"},
|
||||
{"11 months", 330, ">11mo"},
|
||||
{"just under 1 year", 364, ">12mo"},
|
||||
{"exactly 1 year", 365, ">1yr"},
|
||||
{"18 months", 548, ">1yr"}, // Between 1 and 2 years
|
||||
{"just under 2 years", 729, ">1yr"},
|
||||
{"exactly 2 years", 730, ">2yr"},
|
||||
{"3 years", 1095, ">3yr"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var lastAccess time.Time
|
||||
if tt.daysAgo >= 0 {
|
||||
// Create a time that is tt.daysAgo days in the past
|
||||
lastAccess = time.Now().AddDate(0, 0, -tt.daysAgo)
|
||||
}
|
||||
// If daysAgo < 0, lastAccess remains zero value
|
||||
|
||||
got := formatUnusedTime(lastAccess)
|
||||
if got != tt.want {
|
||||
t.Errorf("formatUnusedTime(%d days ago) = %q, want %q", tt.daysAgo, got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,6 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
|
||||
issues = append(issues, "High Memory")
|
||||
}
|
||||
|
||||
// Memory pressure penalty.
|
||||
// Memory pressure penalty.
|
||||
switch mem.Pressure {
|
||||
case "warn":
|
||||
|
||||
Reference in New Issue
Block a user