File: logattr_test.go

package info (click to toggle)
golang-github-cactus-mlog 1.0.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 272 kB
  • sloc: makefile: 2
file content (35 lines) | stat: -rw-r--r-- 743 bytes parent folder | download
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
package mlog

import (
	"testing"

	"gotest.tools/v3/assert"
	is "gotest.tools/v3/assert/cmp"
)

func BenchmarkLogAttrWriteBuf(b *testing.B) {
	buf := &discardSliceWriter{}
	attrs := make([]*Attr, b.N)
	for i := 0; i < 100; i++ {
		attrs = append(attrs, &Attr{
			Key:   randString(10, false),
			Value: randString(25, true),
		})
	}
	b.ResetTimer()
	for i, attr := range attrs {
		attr.writeBuf(buf)
		if i != len(attrs)-1 {
			buf.WriteByte(' ')
		}
	}
}

func TestLogAttrWriteTo(t *testing.T) {
	attr := Attr{"test", "this is \"a test\" of \t some \n a"}
	buf := &sliceBuffer{make([]byte, 0, 1024)}
	attr.writeBuf(buf)
	n := `test="this is \"a test\" of \t some \n a"`
	l := buf.String()
	assert.Check(t, is.Equal(n, l), "did not match")
}