add ext nopwriterclose
Some checks failed
Declarative Tests / test (push) Waiting to run
Declarative Tests / build-fedora (push) Waiting to run
Declarative Tests / build-ubuntu-focal (push) Waiting to run
Lint / golangci-lint (push) Has been cancelled

This commit is contained in:
Matthew Rich 2024-07-17 01:16:51 -07:00
parent 2c1e1de7d1
commit ba19115390
2 changed files with 38 additions and 0 deletions

View 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 }

View 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())
}