Skip to content

Commit 488b47b

Browse files
committed
Enable tests to capture spinner output
Explicitly assign the writer stream for the progress spinner so that tests may override it. The default when not in testing stays the same: the output stream is the colorable stdout.
1 parent 2660561 commit 488b47b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

command/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func repoFork(cmd *cobra.Command, args []string) error {
295295

296296
greenCheck := utils.Green("✓")
297297
out := colorableOut(cmd)
298-
s := utils.Spinner()
298+
s := utils.Spinner(out)
299299
loading := utils.Gray("Forking ") + utils.Bold(utils.Gray(ghrepo.FullName(toFork))) + utils.Gray("...")
300300
s.Suffix = " " + loading
301301
s.FinalMSG = utils.Gray(fmt.Sprintf("- %s\n", loading))

utils/utils.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package utils
22

33
import (
44
"fmt"
5+
"io"
56
"strings"
67
"time"
78

@@ -68,6 +69,8 @@ func Humanize(s string) string {
6869
return strings.Map(h, s)
6970
}
7071

71-
func Spinner() *spinner.Spinner {
72-
return spinner.New(spinner.CharSets[11], 400*time.Millisecond)
72+
func Spinner(w io.Writer) *spinner.Spinner {
73+
s := spinner.New(spinner.CharSets[11], 400*time.Millisecond)
74+
s.Writer = w
75+
return s
7376
}

0 commit comments

Comments
 (0)