Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(otelhttp): unit tests #6151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion instrumentation/net/http/otelhttp/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions instrumentation/net/http/otelhttp/transport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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")
Expand All @@ -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")
Expand Down
Loading