From a952931e8b263786943377489276eda9eb9f001c Mon Sep 17 00:00:00 2001 From: Damien Mathieu <42@dmathieu.com> Date: Mon, 8 Jul 2024 15:29:57 +0200 Subject: [PATCH] Use logtest.AssertRecordEqual in logrus bridge (#5852) Closes #5851 --- bridges/otellogrus/hook_test.go | 33 +-------------------------------- 1 file changed, 1 insertion(+), 32 deletions(-) diff --git a/bridges/otellogrus/hook_test.go b/bridges/otellogrus/hook_test.go index 9a468b34f8b..271ee0f7373 100644 --- a/bridges/otellogrus/hook_test.go +++ b/bridges/otellogrus/hook_test.go @@ -400,43 +400,12 @@ func assertKeyValues(t *testing.T, want, got []log.KeyValue) { } } -func assertBody(t *testing.T, want log.Value, got log.Value) { - t.Helper() - if !got.Equal(want) { - t.Errorf("Body value is not equal:\nwant: %v\ngot: %v", want, got) - } -} - -func assertAttributes(t *testing.T, want, got logtest.EmittedRecord) { - t.Helper() - - var wantAttr []log.KeyValue - want.WalkAttributes(func(kv log.KeyValue) bool { - wantAttr = append(wantAttr, kv) - return true - }) - var gotAttr []log.KeyValue - got.WalkAttributes(func(kv log.KeyValue) bool { - gotAttr = append(gotAttr, kv) - return true - }) - - if !slices.EqualFunc(wantAttr, gotAttr, log.KeyValue.Equal) { - t.Errorf("Attributes are not equal:\nwant: %v\ngot: %v", want, got) - } -} - func assertRecords(t *testing.T, want, got []logtest.EmittedRecord) { t.Helper() assert.Equal(t, len(want), len(got)) for i, j := range want { - assert.Equal(t, j.Timestamp(), got[i].Timestamp()) - assert.Equal(t, j.ObservedTimestamp(), got[i].ObservedTimestamp()) - assert.Equal(t, j.Severity(), got[i].Severity()) - assert.Equal(t, j.SeverityText(), got[i].SeverityText()) - assertBody(t, j.Body(), got[i].Body()) - assertAttributes(t, j, got[i]) + logtest.AssertRecordEqual(t, j.Record, got[i].Record) } }