Skip to content

Commit

Permalink
Merge pull request #123 from bodgit/revert-113
Browse files Browse the repository at this point in the history
Revert PR #113
  • Loading branch information
schollz authored Jul 19, 2022
2 parents 0044010 + 660a827 commit 4ded600
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func DefaultBytes(maxBytes int64, description ...string) *ProgressBar {
OptionThrottle(65*time.Millisecond),
OptionShowCount(),
OptionOnCompletion(func() {
fmt.Printf("\n")
fmt.Fprint(os.Stderr, "\n")
}),
OptionSpinnerType(14),
OptionFullWidth(),
Expand Down Expand Up @@ -375,7 +375,7 @@ func Default(max int64, description ...string) *ProgressBar {
OptionShowCount(),
OptionShowIts(),
OptionOnCompletion(func() {
fmt.Printf("\n")
fmt.Fprint(os.Stderr, "\n")
}),
OptionSpinnerType(14),
OptionFullWidth(),
Expand Down
46 changes: 46 additions & 0 deletions progressbar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,13 +440,36 @@ func TestReaderToFile(t *testing.T) {
defer os.Remove(f.Name())
defer f.Close()

realStdout := os.Stdout
defer func() { os.Stdout = realStdout }()
r, fakeStdout, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = fakeStdout

bar := DefaultBytes(resp.ContentLength)
out := io.MultiWriter(f, bar)
_, err = io.Copy(out, resp.Body)
assert.Nil(t, err)
f.Sync()
f.Seek(0, 0)

if err := fakeStdout.Close(); err != nil {
t.Fatal(err)
}

b, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}

if err := r.Close(); err != nil {
t.Fatal(err)
}

assert.Equal(t, "", string(b))

md5, err := md5sum(f)
assert.Nil(t, err)
assert.Equal(t, "d441819a800f8c90825355dfbede7266", md5)
Expand All @@ -471,13 +494,36 @@ func TestReaderToFileUnknownLength(t *testing.T) {
defer os.Remove(f.Name())
defer f.Close()

realStdout := os.Stdout
defer func() { os.Stdout = realStdout }()
r, fakeStdout, err := os.Pipe()
if err != nil {
t.Fatal(err)
}
os.Stdout = fakeStdout

bar := DefaultBytes(-1, " downloading")
out := io.MultiWriter(f, bar)
_, err = io.Copy(out, resp.Body)
assert.Nil(t, err)
f.Sync()
f.Seek(0, 0)

if err := fakeStdout.Close(); err != nil {
t.Fatal(err)
}

b, err := ioutil.ReadAll(r)
if err != nil {
t.Fatal(err)
}

if err := r.Close(); err != nil {
t.Fatal(err)
}

assert.Equal(t, "", string(b))

md5, err := md5sum(f)
assert.Nil(t, err)
assert.Equal(t, "d441819a800f8c90825355dfbede7266", md5)
Expand Down

0 comments on commit 4ded600

Please sign in to comment.