...
1 package logging
2
3 import (
4 "bytes"
5 "encoding/json"
6 "testing"
7 )
8
9 func TestWithValues(t *testing.T) {
10 buf := bytes.NewBuffer(make([]byte, 0))
11 log := NewLogger(To(buf))
12 log = log.WithValues(OperationKey, Operation{ID: "test_id_nested"})
13 log.Info("hello")
14 out := &LogEntry{}
15 err := json.Unmarshal(buf.Bytes(), out)
16 if err != nil {
17 t.Fatal(err)
18 }
19 if out.Message != "hello" {
20 t.Errorf("got '%s', expected 'hello'", out.Message)
21 }
22 if out.Operation.ID != "test_id_nested" {
23 t.Errorf("got '%s', expected 'test_id_nested'", out.Operation.ID)
24 }
25 }
26
View as plain text