package logging import ( "bytes" "encoding/json" "testing" ) func TestWithValues(t *testing.T) { buf := bytes.NewBuffer(make([]byte, 0)) log := NewLogger(To(buf)) log = log.WithValues(OperationKey, Operation{ID: "test_id_nested"}) log.Info("hello") out := &LogEntry{} err := json.Unmarshal(buf.Bytes(), out) if err != nil { t.Fatal(err) } if out.Message != "hello" { t.Errorf("got '%s', expected 'hello'", out.Message) } if out.Operation.ID != "test_id_nested" { t.Errorf("got '%s', expected 'test_id_nested'", out.Operation.ID) } }