Files
console/output/writer_test.go
andrey 4fdeb73e8a
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
add value vithh error (#1)
Co-authored-by: andrey1s <andrey@4devs.pro>
Reviewed-on: #1
Co-authored-by: andrey <andrey@4devs.io>
Co-committed-by: andrey <andrey@4devs.io>
2022-09-18 21:37:25 +03:00

52 lines
993 B
Go

package output_test
import (
"bytes"
"context"
"testing"
"gitoa.ru/go-4devs/console/output"
"gitoa.ru/go-4devs/console/output/label"
)
func TestNew(t *testing.T) {
t.Parallel()
ctx := context.Background()
buf := bytes.Buffer{}
wr := output.New(&buf, output.FormatString)
cases := map[string]struct {
ex string
kv []label.KeyValue
}{
"message": {
ex: "message",
},
"msg with kv": {
ex: "msg=\"msg with kv\", string key=\"string value\", bool key=\"false\", int key=\"42\"",
kv: []label.KeyValue{
label.String("string key", "string value"),
label.Bool("bool key", false),
label.Int("int key", 42),
},
},
"msg with newline \n": {
ex: "msg=\"msg with newline\", int=\"42\"\n",
kv: []label.KeyValue{
label.Int("int", 42),
},
},
}
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()
}
}