github.com/secman-team/gh-api@v1.8.2/pkg/cmd/run/shared/shared_test.go (about) 1 package shared 2 3 import ( 4 "testing" 5 "time" 6 ) 7 8 func TestPreciseAgo(t *testing.T) { 9 const form = "2006-Jan-02 15:04:05" 10 now, _ := time.Parse(form, "2021-Apr-12 14:00:00") 11 12 cases := map[string]string{ 13 "2021-Apr-12 14:00:00": "0s ago", 14 "2021-Apr-12 13:59:30": "30s ago", 15 "2021-Apr-12 13:59:00": "1m0s ago", 16 "2021-Apr-12 13:30:15": "29m45s ago", 17 "2021-Apr-12 13:00:00": "1h0m0s ago", 18 "2021-Apr-12 02:30:45": "11h29m15s ago", 19 "2021-Apr-11 14:00:00": "24h0m0s ago", 20 "2021-Apr-01 14:00:00": "264h0m0s ago", 21 "2021-Mar-12 14:00:00": "Mar 12, 2021", 22 } 23 24 for createdAt, expected := range cases { 25 d, _ := time.Parse(form, createdAt) 26 got := preciseAgo(now, d) 27 if got != expected { 28 t.Errorf("expected %s but got %s for %s", expected, got, createdAt) 29 } 30 } 31 }