Skip to content

Commit

Permalink
chore(linters): Fix findings found by testifylint: go-require for…
Browse files Browse the repository at this point in the history
… `plugins/outputs` (#15985)

(cherry picked from commit 4386535)
  • Loading branch information
zak-pawel authored and srebhan committed Oct 28, 2024
1 parent 8f62670 commit 69d4b3a
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 225 deletions.
18 changes: 14 additions & 4 deletions plugins/outputs/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ func TestFileBoth(t *testing.T) {
require.NoError(t, err)
}

type erroredString struct {
str string
err error
}

func TestFileStdout(t *testing.T) {
// keep backup of the real stdout
old := os.Stdout
Expand Down Expand Up @@ -261,13 +266,17 @@ func TestFileStdout(t *testing.T) {
err = f.Close()
require.NoError(t, err)

outC := make(chan string)
outC := make(chan erroredString)
// copy the output in a separate goroutine so printing can't block indefinitely
go func() {
var buf bytes.Buffer
_, err := io.Copy(&buf, r)
require.NoError(t, err)
outC <- buf.String()
if err != nil {
outC <- erroredString{err: err}
return
}

outC <- erroredString{str: buf.String()}
}()

// back to normal state
Expand All @@ -278,7 +287,8 @@ func TestFileStdout(t *testing.T) {
os.Stdout = old
out := <-outC

require.Equal(t, expNewFile, out)
require.NoError(t, out.err)
require.Equal(t, expNewFile, out.str)
}

func createFile(t *testing.T) *os.File {
Expand Down
Loading

0 comments on commit 69d4b3a

Please sign in to comment.