Skip to content

Commit

Permalink
Add a test for writeBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
banjoh committed Sep 15, 2023
1 parent 8266027 commit 61efb30
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pkg/redact/multi_line_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package redact
import (
"bytes"
"io"
"strings"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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())
})
}
}

0 comments on commit 61efb30

Please sign in to comment.