From ba1911539074fd1f20d66536cc65eab61168e586 Mon Sep 17 00:00:00 2001 From: Matthew Rich Date: Wed, 17 Jul 2024 01:16:51 -0700 Subject: [PATCH] add ext nopwriterclose --- internal/ext/nopwritecloser.go | 17 +++++++++++++++++ internal/ext/nopwritecloser_test.go | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 internal/ext/nopwritecloser.go create mode 100644 internal/ext/nopwritecloser_test.go 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()) +}