File: writer_test.go

package info (click to toggle)
golang-github-containers-common 0.50.1%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 4,440 kB
  • sloc: makefile: 118; sh: 46
file content (43 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package report

import (
	"bytes"
	"testing"

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

func TestNewWriter(t *testing.T) {
	testCases := []struct {
		input    string
		expected string
	}{
		{"Hello\tWorld", "Hello:World"},
		{"Be\tGood", "Be::Good"},
	}

	var buf bytes.Buffer
	for _, tc := range testCases {
		tc := tc
		t.Run(tc.input, func(t *testing.T) {
			w, err := NewWriter(&buf, 4, 8, 1, ':', 0)
			assert.NoError(t, err)

			_, err = w.Write([]byte(tc.input))
			assert.NoError(t, err)
			w.Flush()
			assert.Equal(t, tc.expected, buf.String())
		})
		buf.Reset()
	}
}

func TestNewWriterDefault(t *testing.T) {
	var buf bytes.Buffer
	w, err := NewWriterDefault(&buf)
	assert.NoError(t, err)
	_, err = w.Write([]byte("a46001bfea3a4172b46c173101208244\tRandom\tuuid"))
	assert.NoError(t, err)
	w.Flush()
	assert.Equal(t, "a46001bfea3a4172b46c173101208244  Random      uuid", buf.String())
}