(t *testing.T)
| 229 | } |
| 230 | |
| 231 | func TestProgressbarPrinter_OutputToWriters(t *testing.T) { |
| 232 | testCases := map[string]struct { |
| 233 | action func(*pterm.ProgressbarPrinter) |
| 234 | expectOutputToContain string |
| 235 | }{ |
| 236 | "ExpectUpdatedTitleToBeWrittenToStderr": { |
| 237 | action: func(pb *pterm.ProgressbarPrinter) { |
| 238 | pb.UpdateTitle("Updated text") |
| 239 | }, |
| 240 | expectOutputToContain: "Updated text", |
| 241 | }, |
| 242 | } |
| 243 | |
| 244 | for testTitle, testCase := range testCases { |
| 245 | t.Run(testTitle, func(t *testing.T) { |
| 246 | stderr, err := testza.CaptureStderr(func(w io.Writer) error { |
| 247 | pb, err := pterm.DefaultProgressbar.WithTitle("Hello world").WithWriter(os.Stderr).Start() |
| 248 | time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't outputted |
| 249 | testza.AssertNoError(t, err) |
| 250 | testCase.action(pb) |
| 251 | time.Sleep(time.Second) // Required otherwise the goroutine doesn't run and the text isn't updated |
| 252 | return nil |
| 253 | }) |
| 254 | |
| 255 | testza.AssertNoError(t, err) |
| 256 | testza.AssertContains(t, stderr, "Hello world") |
| 257 | testza.AssertContains(t, stderr, testCase.expectOutputToContain) |
| 258 | }) |
| 259 | } |
| 260 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…