Skip to content

Commit

Permalink
🐛 Fix test race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed May 10, 2022
1 parent 8fee630 commit 636920d
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@ func Test_openAndTemplate(t *testing.T) {
}

var stdoutBuf strings.Builder
ch := make(chan struct{})
go func() {
_, _ = io.Copy(&stdoutBuf, r)
ch <- struct{}{}
}()
defer func(w *os.File) {
_ = w.Close()
Expand Down Expand Up @@ -196,6 +198,9 @@ func Test_openAndTemplate(t *testing.T) {
return
}

_ = w.Close()
<-ch

if (stdoutBuf.Len() != 0) != tt.wantStdout {
t.Errorf("openAndTemplate() got stdout len = %v, want stdout %v", stdoutBuf.Len(), tt.wantStdout)
return
Expand Down

0 comments on commit 636920d

Please sign in to comment.