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