mwc: linter fixes

This commit is contained in:
2025-11-15 20:39:21 -08:00
parent ecc7e5ab1e
commit 9fb93a3802
2 changed files with 14 additions and 13 deletions

View File

@@ -8,15 +8,15 @@ type mwc struct {
} }
// Write implements the Writer interface. // Write implements the Writer interface.
func (t *mwc) Write(p []byte) (n int, err error) { func (t *mwc) Write(p []byte) (int, error) {
for _, w := range t.wcs { for _, w := range t.wcs {
n, err = w.Write(p) n, err := w.Write(p)
if err != nil { if err != nil {
return return n, err
} }
if n != len(p) { if n != len(p) {
err = io.ErrShortWrite err = io.ErrShortWrite
return return n, err
} }
} }
return len(p), nil return len(p), nil

View File

@@ -1,10 +1,11 @@
package mwc package mwc_test
import ( import (
"bytes" "bytes"
"testing" "testing"
"git.wntrmute.dev/kyle/goutils/assert" "git.wntrmute.dev/kyle/goutils/assert"
"git.wntrmute.dev/kyle/goutils/mwc"
"git.wntrmute.dev/kyle/goutils/testio" "git.wntrmute.dev/kyle/goutils/testio"
) )
@@ -12,7 +13,7 @@ func TestMWC(t *testing.T) {
buf1 := testio.NewBufCloser(nil) buf1 := testio.NewBufCloser(nil)
buf2 := testio.NewBufCloser(nil) buf2 := testio.NewBufCloser(nil)
mwc := MultiWriteCloser(buf1, buf2) mwc := mwc.MultiWriteCloser(buf1, buf2)
_, err := mwc.Write([]byte("hello, world")) _, err := mwc.Write([]byte("hello, world"))
assert.NoErrorT(t, err) assert.NoErrorT(t, err)
@@ -30,15 +31,15 @@ func TestMWCShort(t *testing.T) {
buf3 := testio.NewBrokenWriter(5) buf3 := testio.NewBrokenWriter(5)
buf4 := testio.NewSilentBrokenWriter(5) buf4 := testio.NewSilentBrokenWriter(5)
mwc := MultiWriteCloser(buf1, buf2, buf3) multiWriter := mwc.MultiWriteCloser(buf1, buf2, buf3)
defer mwc.Close() defer multiWriter.Close()
_, err := mwc.Write([]byte("hello, world")) _, err := multiWriter.Write([]byte("hello, world"))
assert.ErrorT(t, err, "expected a short write error", "but no error occurred") assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
mwc.Close() multiWriter.Close()
mwc = MultiWriteCloser(buf1, buf2, buf4) multiWriter = mwc.MultiWriteCloser(buf1, buf2, buf4)
_, err = mwc.Write([]byte("hello, world")) _, err = multiWriter.Write([]byte("hello, world"))
assert.ErrorT(t, err, "expected a short write error", "but no error occurred") assert.ErrorT(t, err, "expected a short write error", "but no error occurred")
} }
@@ -47,7 +48,7 @@ func TestMWCClose(t *testing.T) {
buf2 := testio.NewBufCloser(nil) buf2 := testio.NewBufCloser(nil)
buf3 := testio.NewBrokenCloser(nil) buf3 := testio.NewBrokenCloser(nil)
mwc := MultiWriteCloser(buf1, buf2, buf3) mwc := mwc.MultiWriteCloser(buf1, buf2, buf3)
_, err := mwc.Write([]byte("hello, world")) _, err := mwc.Write([]byte("hello, world"))
assert.NoErrorT(t, err) assert.NoErrorT(t, err)