diff --git a/internal/ext/nopwritecloser.go b/internal/ext/nopwritecloser.go new file mode 100644 index 0000000..0f8f984 --- /dev/null +++ b/internal/ext/nopwritecloser.go @@ -0,0 +1,17 @@ +// Copyright 2024 Matthew Rich . 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 } diff --git a/internal/ext/nopwritecloser_test.go b/internal/ext/nopwritecloser_test.go new file mode 100644 index 0000000..eb6a2a6 --- /dev/null +++ b/internal/ext/nopwritecloser_test.go @@ -0,0 +1,21 @@ +// Copyright 2024 Matthew Rich . 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()) +}