You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
993 B

package output_test
4 years ago
import (
"bytes"
"context"
"testing"
"gitoa.ru/go-4devs/console/output"
4 years ago
"gitoa.ru/go-4devs/console/output/label"
4 years ago
)
func TestNew(t *testing.T) {
t.Parallel()
4 years ago
ctx := context.Background()
buf := bytes.Buffer{}
wr := output.New(&buf, output.FormatString)
4 years ago
cases := map[string]struct {
ex string
4 years ago
kv []label.KeyValue
4 years ago
}{
"message": {
ex: "message",
},
"msg with kv": {
ex: "msg=\"msg with kv\", string key=\"string value\", bool key=\"false\", int key=\"42\"",
4 years ago
kv: []label.KeyValue{
label.String("string key", "string value"),
label.Bool("bool key", false),
label.Int("int key", 42),
4 years ago
},
},
"msg with newline \n": {
ex: "msg=\"msg with newline\", int=\"42\"\n",
4 years ago
kv: []label.KeyValue{
label.Int("int", 42),
4 years ago
},
},
}
for msg, data := range cases {
wr.InfoKV(ctx, msg, data.kv...)
if data.ex != buf.String() {
t.Errorf("message not equals expext:%s, got:%s", data.ex, buf.String())
}
buf.Reset()
}
}