From 61efb304c998f476838ef175f1b8a372e4a0db6e Mon Sep 17 00:00:00 2001 From: Evans Mungai Date: Fri, 15 Sep 2023 11:26:53 +0100 Subject: [PATCH] Add a test for writeBytes --- pkg/redact/multi_line_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/pkg/redact/multi_line_test.go b/pkg/redact/multi_line_test.go index 81bdb0959..04f199517 100644 --- a/pkg/redact/multi_line_test.go +++ b/pkg/redact/multi_line_test.go @@ -3,8 +3,10 @@ package redact import ( "bytes" "io" + "strings" "testing" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -109,3 +111,32 @@ func Test_NewMultiLineRedactor(t *testing.T) { }) } } + +func Test_writeBytes(t *testing.T) { + tests := []struct { + name string + inputBytes [][]byte + want string + }{ + { + name: "No newline", + inputBytes: [][]byte{[]byte("hello"), []byte("world")}, + want: "helloworld", + }, + { + name: "With newline", + inputBytes: [][]byte{[]byte("hello"), NEW_LINE, []byte("world"), NEW_LINE}, + want: "hello\nworld\n", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var w strings.Builder + err := writeBytes(&w, tt.inputBytes...) + require.NoError(t, err) + + assert.Equal(t, tt.want, w.String()) + }) + } +}