package cli import ( "strings" "testing" ) func TestBarStaysWithinItsWidth(t *testing.T) { // It is drawn from counts that can disagree briefly — a GPU freed between // two reads — and a bar that overruns its column wrecks the table it is in. for _, tc := range [][2]int{{0, 0}, {0, 8}, {8, 8}, {9, 8}, {100, 8}} { got := bar(tc[0], tc[1]) if tc[1] == 0 { if got != "" { t.Errorf("bar(%d,%d) = %q, want empty for an empty class", tc[0], tc[1], got) } continue } if n := strings.Count(got, "#") + strings.Count(got, "."); n != 20 { t.Errorf("bar(%d,%d) drew %d cells: %q", tc[0], tc[1], n, got) } } } func TestIdleColumnDistinguishesUnknownFromIdle(t *testing.T) { // Every replica looks unreported before its first request and after a // router restart. Showing that as a very large duration would make an // untouched fleet read as an abandoned one. if got := idleColumn(-1); got != "-" { t.Errorf("idleColumn(-1) = %q, want a dash", got) } if got := idleColumn(90); got != "1m30s" { t.Errorf("idleColumn(90) = %q", got) } }