Download this file
| 1 | package console |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "time" |
| 6 | ) |
| 7 | |
| 8 | func TestUntilHelper(t *testing.T) { |
| 9 | // humanAge always renders both components in the 1-24h bucket |
| 10 | // ("4h0m", never bare "4h"), and untilText's own time.Until call runs a |
| 11 | // few microseconds after this Add — just enough for the floored minute |
| 12 | // to round down once. "~4h1m" covers the (vanishingly unlikely) case |
| 13 | // where the call lands before that rollover. |
| 14 | if got := untilText(time.Now().Add(4*time.Hour + time.Minute)); got != "~4h0m" && got != "~4h1m" { |
| 15 | t.Errorf("until ~4h = %q", got) |
| 16 | } |
| 17 | if got := untilText(time.Time{}); got != "now" { |
| 18 | t.Errorf("until zero = %q", got) |
| 19 | } |
| 20 | if got := untilText(time.Now().Add(-time.Hour)); got != "now" { |
| 21 | t.Errorf("until past = %q", got) |
| 22 | } |
| 23 | } |
| 24 | |