(t *testing.T)
| 74 | } |
| 75 | |
| 76 | func TestPrintWithDimensions_LinesFitTerminalWidth(t *testing.T) { |
| 77 | testCases := []struct { |
| 78 | name string |
| 79 | taskID string |
| 80 | status string |
| 81 | details string |
| 82 | terminalWidth int |
| 83 | }{ |
| 84 | { |
| 85 | name: "short task fits wide terminal", |
| 86 | taskID: "Image foo", |
| 87 | status: "Pulling", |
| 88 | details: "layer abc123", |
| 89 | terminalWidth: 100, |
| 90 | }, |
| 91 | { |
| 92 | name: "long details truncated to fit", |
| 93 | taskID: "Image foo", |
| 94 | status: "Pulling", |
| 95 | details: "downloading layer sha256:abc123def456789xyz0123456789abcdef", |
| 96 | terminalWidth: 50, |
| 97 | }, |
| 98 | { |
| 99 | name: "long taskID truncated to fit", |
| 100 | taskID: "very-long-image-name-that-exceeds-terminal-width", |
| 101 | status: "Pulling", |
| 102 | details: "", |
| 103 | terminalWidth: 40, |
| 104 | }, |
| 105 | { |
| 106 | name: "both long taskID and details", |
| 107 | taskID: "my-very-long-service-name-here", |
| 108 | status: "Downloading", |
| 109 | details: "layer sha256:abc123def456789xyz0123456789", |
| 110 | terminalWidth: 50, |
| 111 | }, |
| 112 | { |
| 113 | name: "narrow terminal", |
| 114 | taskID: "service-name", |
| 115 | status: "Pulling", |
| 116 | details: "some details", |
| 117 | terminalWidth: 35, |
| 118 | }, |
| 119 | } |
| 120 | |
| 121 | for _, tc := range testCases { |
| 122 | t.Run(tc.name, func(t *testing.T) { |
| 123 | w, buf := newTestWriter() |
| 124 | addTask(w, tc.taskID, tc.status, tc.details, api.Working) |
| 125 | |
| 126 | w.printWithDimensions(tc.terminalWidth, 24) |
| 127 | |
| 128 | lines := extractLines(buf) |
| 129 | for i, line := range lines { |
| 130 | lineLen := lenAnsi(line) |
| 131 | assert.Assert(t, lineLen <= tc.terminalWidth, |
| 132 | "line %d has length %d which exceeds terminal width %d: %q", |
| 133 | i, lineLen, tc.terminalWidth, line) |
nothing calls this directly
no test coverage detected