It is not "meant for tests internal to the http package". It's meant for
tests of users of the `net/http` package. That is, implementations of the
`http.Handler` interface.
In the context of the standard library, that is what "general purpose HTTP
testing" means.
On Tue, Oct 17, 2023 at 10:44 AM S
And so: https://github.com/golang/go/issues/63589
On Tuesday, October 17, 2023 at 10:44:04 AM UTC+2 Simon Walter wrote:
> It is good practice to use test lang/tools/libs/etc different from what
> you are using in your actual code.
>
> If the author has meant for the httptest package as general p
It is good practice to use test lang/tools/libs/etc different from what you
are using in your actual code.
If the author has meant for the httptest package as general purpose HTTP
testing library, then, I will argue that such defaults are incorrect. It is
incorrect even if the intended purpose
To be clear: The behavior of an `http.ResponseWriter` to implicitly use a
200 status code if no explicit WriteHeader call is made is documented:
https://pkg.go.dev/net/http#ResponseWriter.WriteHeader
I really think it is a bad (or at least strange) idea to claim to implement
`http.ResponseWriter` w
It seems to me that the fact that the functions accept and return types
from `net/http` (like `http.ResponseWriter` and `http.Handler`) and given
that it's nested below `net/http` should make it fairly obvious that it's
meant to be used with `net/http`. I also genuinely don't understand what
the in
Axel, thanks for providing some context.
I suppose it is better for me to think of the httptest package as specific
to the http package - although this is not explicitly stated: "Package
httptest provides utilities for HTTP testing"
This seems misleading as is the case with this '200' default.
If you want to argue that `net/http` should not set the response code to
200 by default, I would be inclined to agree. I don't particularly like
that the API even *allows* you not to explicitly set a response code. But
it does. And while it does, the best test is one that matches the behavior
of th
How does that explain why it is a good idea?
Perhaps my concern is not clear enough.
For example:
n := 5
funcThatShouldSetNtoFive(&n)
if n != 5 {
panic("n is not 5)
}
This is not a good test.
I can check if the value has changed by:
n := 0
funcThatShouldSetNtoFive(&n)
if n != 5 {
panic("n
A default `net/http` server also uses 200 as the default response code. The
behavior of an `http.Handler` not setting a response code should be the
same, if it uses `httptest`, as if it uses `net/http`.
On Sun, Oct 15, 2023 at 5:17 PM Simon Walter wrote:
> Hi all,
>
> What is the reason that Res
Hi all,
What is the reason that ResponseRecorder HTTP status code defaults to 200?
https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/net/http/httptest/recorder.go;drc=ff14e844d26090e09aa335d836f737c09a7a0402;l=55
https://cs.opensource.google/go/go/+/refs/tags/go1.21.3:src/net/http/http
10 matches
Mail list logo