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 is not 5)
}
That's a bit more sensible.
Wouldn't it be less risky for a test to fail by default? Removal of the
call to funcThatShouldSetNtoFive, IMO, should result in failure.
On Sunday, October 15, 2023 at 6:10:36 PM UTC+2 Axel Wagner wrote:
> 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 <[email protected]> wrote:
>
>> 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/httptest/recorder.go;drc=ff14e844d26090e09aa335d836f737c09a7a0402;l=196
>>
>> Can someone explain to me why this is a good idea? Would it not make more
>> sense to set it to a value that is not a valid HTTP response code such as 0?
>>
>> Simon
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/321a84fa-3aeb-4f3a-ba4f-a05e797652d6n%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/golang-nuts/321a84fa-3aeb-4f3a-ba4f-a05e797652d6n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/df053fb7-70bf-483d-afd6-4caee9937aa6n%40googlegroups.com.