From e27afb982f1fe6dcf3496b91711ae0ddd8eccba7 Mon Sep 17 00:00:00 2001 From: 5ylar Date: Tue, 24 Sep 2024 10:43:59 +0700 Subject: [PATCH] refactor(otelhttp): unit tests --- instrumentation/net/http/otelhttp/transport.go | 2 +- instrumentation/net/http/otelhttp/transport_test.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/instrumentation/net/http/otelhttp/transport.go b/instrumentation/net/http/otelhttp/transport.go index b4119d3438b..cc918367511 100644 --- a/instrumentation/net/http/otelhttp/transport.go +++ b/instrumentation/net/http/otelhttp/transport.go @@ -200,7 +200,7 @@ func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error) { t.latencyMeasure.Record(ctx, elapsedTime, o) - return res, err + return res, nil } func (t *Transport) metricAttributesFromRequest(r *http.Request) []attribute.KeyValue { diff --git a/instrumentation/net/http/otelhttp/transport_test.go b/instrumentation/net/http/otelhttp/transport_test.go index a88d45c20b9..106acf88809 100644 --- a/instrumentation/net/http/otelhttp/transport_test.go +++ b/instrumentation/net/http/otelhttp/transport_test.go @@ -248,7 +248,7 @@ func TestWrappedBodyRead(t *testing.T) { s := new(span) called := false record := func(numBytes int64) { called = true } - wb := &wrappedBody{span: trace.Span(s), record: record, body: readCloser{}} + wb := newWrappedBody(s, record, readCloser{}) n, err := wb.Read([]byte{}) assert.Equal(t, readSize, n, "wrappedBody returned wrong bytes") assert.NoError(t, err) @@ -264,7 +264,7 @@ func TestWrappedBodyReadEOFError(t *testing.T) { called = true numRecorded = numBytes } - wb := &wrappedBody{span: trace.Span(s), record: record, body: readCloser{readErr: io.EOF}} + wb := newWrappedBody(s, record, readCloser{readErr: io.EOF}) n, err := wb.Read([]byte{}) assert.Equal(t, readSize, n, "wrappedBody returned wrong bytes") assert.Equal(t, io.EOF, err) @@ -278,7 +278,7 @@ func TestWrappedBodyReadError(t *testing.T) { called := false record := func(int64) { called = true } expectedErr := errors.New("test") - wb := &wrappedBody{span: trace.Span(s), record: record, body: readCloser{readErr: expectedErr}} + wb := newWrappedBody(s, record, readCloser{readErr: expectedErr}) n, err := wb.Read([]byte{}) assert.Equal(t, readSize, n, "wrappedBody returned wrong bytes") assert.Equal(t, expectedErr, err) @@ -290,7 +290,7 @@ func TestWrappedBodyClose(t *testing.T) { s := new(span) called := false record := func(int64) { called = true } - wb := &wrappedBody{span: trace.Span(s), record: record, body: readCloser{}} + wb := newWrappedBody(s, record, readCloser{}) assert.NoError(t, wb.Close()) s.assert(t, true, nil, codes.Unset, "") assert.True(t, called, "record should have been called") @@ -308,7 +308,7 @@ func TestWrappedBodyCloseError(t *testing.T) { called := false record := func(int64) { called = true } expectedErr := errors.New("test") - wb := &wrappedBody{span: trace.Span(s), record: record, body: readCloser{closeErr: expectedErr}} + wb := newWrappedBody(s, record, readCloser{closeErr: expectedErr}) assert.Equal(t, expectedErr, wb.Close()) s.assert(t, true, nil, codes.Unset, "") assert.True(t, called, "record should have been called")