add ext nopwriterclose
This commit is contained in:
parent
2c1e1de7d1
commit
ba19115390
17
internal/ext/nopwritecloser.go
Normal file
17
internal/ext/nopwritecloser.go
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||
|
||||
package ext
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
func WriteNopCloser(w io.Writer) io.WriteCloser {
|
||||
return writeNopCloser{w}
|
||||
}
|
||||
|
||||
type writeNopCloser struct {
|
||||
io.Writer
|
||||
}
|
||||
|
||||
func (writeNopCloser) Close() error { return nil }
|
21
internal/ext/nopwritecloser_test.go
Normal file
21
internal/ext/nopwritecloser_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2024 Matthew Rich <matthewrich.conf@gmail.com>. All rights reserved.
|
||||
|
||||
package ext
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"strings"
|
||||
_ "fmt"
|
||||
_ "log"
|
||||
)
|
||||
|
||||
func TestNewWriteNopCloser(t *testing.T) {
|
||||
var testWriter strings.Builder
|
||||
closer := WriteNopCloser(&testWriter)
|
||||
assert.NotNil(t, closer)
|
||||
_, err := closer.Write([]byte("test data"))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, "test data", testWriter.String())
|
||||
assert.Nil(t, closer.Close())
|
||||
}
|
Loading…
Reference in New Issue
Block a user