1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 15:39:42 +00:00

Merge branch 'pr-348'

This commit is contained in:
Tw93
2026-01-22 17:22:48 +08:00
2 changed files with 39 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package main
import ( import (
"strings" "strings"
"testing" "testing"
"time"
) )
func TestRuneWidth(t *testing.T) { 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)
}
})
}
}

View File

@@ -69,7 +69,6 @@ func calculateHealthScore(cpu CPUStatus, mem MemoryStatus, disks []DiskStatus, d
issues = append(issues, "High Memory") issues = append(issues, "High Memory")
} }
// Memory pressure penalty.
// Memory pressure penalty. // Memory pressure penalty.
switch mem.Pressure { switch mem.Pressure {
case "warn": case "warn":