(t *testing.T)
| 34 | } |
| 35 | |
| 36 | func TestFuzzyAgoAbbr(t *testing.T) { |
| 37 | const form = "2006-Jan-02 15:04:05" |
| 38 | now, _ := time.Parse(form, "2020-Nov-22 14:00:00") |
| 39 | cases := map[string]string{ |
| 40 | "2020-Nov-22 14:00:00": "0m", |
| 41 | "2020-Nov-22 13:59:00": "1m", |
| 42 | "2020-Nov-22 13:30:00": "30m", |
| 43 | "2020-Nov-22 13:00:00": "1h", |
| 44 | "2020-Nov-22 02:00:00": "12h", |
| 45 | "2020-Nov-21 14:00:00": "1d", |
| 46 | "2020-Nov-07 14:00:00": "15d", |
| 47 | "2020-Oct-24 14:00:00": "29d", |
| 48 | "2020-Oct-23 14:00:00": "Oct 23, 2020", |
| 49 | "2019-Nov-22 14:00:00": "Nov 22, 2019", |
| 50 | } |
| 51 | for createdAt, expected := range cases { |
| 52 | d, err := time.Parse(form, createdAt) |
| 53 | assert.NoError(t, err) |
| 54 | fuzzy := FuzzyAgoAbbr(now, d) |
| 55 | assert.Equal(t, expected, fuzzy) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | func TestFormatSlice(t *testing.T) { |
| 60 | tests := []struct { |
nothing calls this directly
no test coverage detected