aboutsummaryrefslogtreecommitdiff
path: root/gui/internal/model/plan_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'gui/internal/model/plan_test.go')
-rw-r--r--gui/internal/model/plan_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/gui/internal/model/plan_test.go b/gui/internal/model/plan_test.go
index ecbb81d..a54768c 100644
--- a/gui/internal/model/plan_test.go
+++ b/gui/internal/model/plan_test.go
@@ -361,3 +361,50 @@ func TestReplaceSelected(t *testing.T) {
t.Errorf("the unchecked file did not stay put: %v", err)
}
}
+
+// TestRowsCarrySizeAndAge: a plan's rows know how big each file is and when
+// it was last written, for the columns that show them.
+func TestRowsCarrySizeAndAge(t *testing.T) {
+ conf := "(path \"~/dl\")\n(rule \"all\" (move \"Out\"))\n"
+ e, h := sandboxDir(t, conf, map[string]string{"a.pdf": "three bytes and more"})
+ tab := planTab(t, e)
+ if len(tab.Rows) != 1 {
+ t.Fatalf("rows = %+v", tab.Rows)
+ }
+ fi, err := os.Stat(filepath.Join(h, "dl", "a.pdf"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if tab.Rows[0].Size != fi.Size() {
+ t.Errorf("size = %d, want %d", tab.Rows[0].Size, fi.Size())
+ }
+ if !tab.Rows[0].ModTime.Equal(fi.ModTime()) {
+ t.Errorf("mtime = %v, want %v", tab.Rows[0].ModTime, fi.ModTime())
+ }
+}
+
+// TestAgeText: the units krino's own (age ...) test uses, and nothing for a
+// file whose time is unknown.
+func TestAgeText(t *testing.T) {
+ now := time.Date(2026, 9, 17, 12, 0, 0, 0, time.UTC)
+ for _, c := range []struct {
+ ago time.Duration
+ want string
+ }{
+ {30 * time.Minute, "30m"},
+ {5 * time.Hour, "5h"},
+ {3 * 24 * time.Hour, "3d"},
+ {3 * 7 * 24 * time.Hour, "3w"},
+ {3 * 365 * 24 * time.Hour, "3y"},
+ } {
+ if got := AgeText(now.Add(-c.ago), now); got != c.want {
+ t.Errorf("%v ago = %q, want %q", c.ago, got, c.want)
+ }
+ }
+ if got := AgeText(time.Time{}, now); got != "" {
+ t.Errorf("an unknown time = %q, want nothing", got)
+ }
+ if got := AgeText(now.Add(time.Hour), now); got != "0m" {
+ t.Errorf("a file from the future = %q, want 0m", got)
+ }
+}