Skip to content

Conversation

@henripqt
Copy link
Contributor

@henripqt henripqt commented Mar 28, 2025

What :

  • Check that the response body is empty by using the [http.NoBody] variable as the http.Client and http.Transport always guarantees that the body will never be nil hence the condition response.Body == nil is irrelevant in real word scenarios.
  • Adjust test accordingly

source :

https://cs.opensource.google/go/go/+/refs/tags/go1.24.1:src/net/http/response.go

	// Body represents the response body.
	//
	// The response body is streamed on demand as the Body field
	// is read. If the network connection fails or the server
	// terminates the response, Body.Read calls return an error.
	//
	// The http Client and Transport guarantee that Body is always
	// non-nil, even on responses without a body or responses with
	// a zero-length body. It is the caller's responsibility to
	// close Body. The default HTTP client's Transport may not
	// reuse HTTP/1.x "keep-alive" TCP connections if the Body is
	// not read to completion and closed.
	//
	// The Body is automatically dechunked if the server replied
	// with a "chunked" Transfer-Encoding.
	//
	// As of Go 1.12, the Body will also implement io.Writer
	// on a successful "101 Switching Protocols" response,
	// as used by WebSockets and HTTP/2's "h2c" mode.
	Body io.ReadCloser

Suggestion :

Maybe we could adjust the test to use an http.TestServer and issue requests to it in order to simulate real world scenarios ?
Happy to do another PR to introduce these changes if you wish.

@codecov
Copy link

codecov bot commented Apr 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@9a731fd). Learn more about missing BASE report.
Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #131   +/-   ##
=======================================
  Coverage        ?   99.74%           
=======================================
  Files           ?       29           
  Lines           ?     3163           
  Branches        ?        0           
=======================================
  Hits            ?     3155           
  Misses          ?        8           
  Partials        ?        0           
Flag Coverage Δ
unittests 99.74% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@daveshanley daveshanley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Thank you for catching this.

@daveshanley daveshanley merged commit 9ac207b into pb33f:main Apr 8, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants