MCPcopy
hub / github.com/docker/compose / TestPrintWithDimensions_TimerIsRightAligned

Function TestPrintWithDimensions_TimerIsRightAligned

cmd/display/tty_test.go:471–530  ·  cmd/display/tty_test.go::TestPrintWithDimensions_TimerIsRightAligned
(t *testing.T)

Source from the content-addressed store, hash-verified

469}
470
471func TestPrintWithDimensions_TimerIsRightAligned(t *testing.T) {
472 w, buf := newTestWriter()
473
474 base := time.Unix(0, 0)
475
476 // Long timer: "10.6s" (length 5)
477 longTask := &task{
478 ID: "task-long",
479 parents: make(map[string]struct{}),
480 startTime: base,
481 endTime: base.Add(10*time.Second + 600*time.Millisecond),
482 text: "Pulled",
483 status: api.Done,
484 spinner: NewSpinner(),
485 }
486 longTask.spinner.Stop()
487 w.tasks[longTask.ID] = longTask
488 w.ids = append(w.ids, longTask.ID)
489
490 // Short timer: "0.0s" (length 4)
491 shortTask := &task{
492 ID: "task-short",
493 parents: make(map[string]struct{}),
494 startTime: base,
495 endTime: base,
496 text: "Pulled",
497 status: api.Done,
498 spinner: NewSpinner(),
499 }
500 shortTask.spinner.Stop()
501 w.tasks[shortTask.ID] = shortTask
502 w.ids = append(w.ids, shortTask.ID)
503
504 terminalWidth := 80
505 w.printWithDimensions(terminalWidth, 24)
506
507 // Strip ANSI codes from output and split by newline
508 stripped := stripAnsi(buf.String())
509 lines := strings.Split(stripped, "\n")
510
511 var nonEmptyLines []string
512 for _, line := range lines {
513 if strings.TrimSpace(line) != "" {
514 nonEmptyLines = append(nonEmptyLines, line)
515 }
516 }
517
518 // Find the line containing the shorter timer.
519 var shortLine string
520 for _, line := range nonEmptyLines {
521 if strings.Contains(line, "0.0s") {
522 shortLine = line
523 break
524 }
525 }
526 assert.Assert(t, shortLine != "", "expected to find a rendered line containing \"0.0s\"")
527 assert.Assert(t, strings.HasSuffix(shortLine, "0.0s"),
528 "short timer should be left-padded (no trailing spaces after the timer); got: %q",

Callers

nothing calls this directly

Calls 7

newTestWriterFunction · 0.85
NewSpinnerFunction · 0.85
stripAnsiFunction · 0.85
printWithDimensionsMethod · 0.80
StopMethod · 0.65
AddMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected