github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/hud/format_test.go (about) 1 package hud 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 type durationCase struct { 12 dur time.Duration 13 deploy string 14 build string 15 } 16 17 func TestFormatDurations(t *testing.T) { 18 table := []durationCase{ 19 {time.Second, "<5s", "1.0s"}, 20 {20 * time.Second, "<30s", "20s"}, 21 {40 * time.Second, "<45s", "40s"}, 22 {50 * time.Second, "<1m", "50s"}, 23 {70 * time.Second, "1m", "1m"}, 24 {150 * time.Second, "2m", "2m"}, 25 {4000 * time.Second, "1h", "1h"}, 26 27 // there used to be a bug where the UI would flip from 28 // "10.0s" to "10s", which looked weird. 29 {10*time.Second - 100*time.Millisecond, "<15s", "9.9s"}, 30 {10*time.Second - 51*time.Millisecond, "<15s", "9.9s"}, 31 {10*time.Second - 50*time.Millisecond, "<15s", "10s"}, 32 {10*time.Second - time.Millisecond, "<15s", "10s"}, 33 {10 * time.Second, "<15s", "10s"}, 34 {10*time.Second + time.Millisecond, "<15s", "10s"}, 35 } 36 37 for i, entry := range table { 38 t.Run(fmt.Sprintf("Case%d", i), func(t *testing.T) { 39 assert.Equal(t, entry.build, formatBuildDuration(entry.dur), "formatBuildDuration") 40 assert.Equal(t, entry.deploy, formatDeployAge(entry.dur), "formatDeployAge") 41 }) 42 } 43 }