We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
go version
$ go version go version go1.16.5 darwin/arm64
yes
go env
$ go env GO111MODULE="" GOARCH="arm64" GOBIN="" GOCACHE="/Users/andig/Library/Caches/go-build" GOENV="/Users/andig/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="arm64" GOHOSTOS="darwin" GOINSECURE="" GOMODCACHE="/Users/andig/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/andig/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/opt/homebrew/Cellar/go/1.16.5/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/opt/homebrew/Cellar/go/1.16.5/libexec/pkg/tool/darwin_arm64" GOVCS="" GOVERSION="go1.16.5" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="/Users/andig/htdocs/evcc/go.mod" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/sv/rs_453y57xj86xsbz3kw1mbc0000gn/T/go-build3556353379=/tmp/go-build -gno-record-gcc-switches -fno-common"
Testing an http client doing JSON request using httptest my test always failed.
httptest
This is the test:
func TestHttp(t *testing.T) { ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = fmt.Println(w, `{"list":[{"useMeter":true}]}`) })) defer ts.Close() resp, err := http.Get(ts.URL) if err != nil { panic(err) } defer resp.Body.Close() b, err := io.ReadAll(resp.Body) if err != nil { panic(err) } t.Log(string(b)) var res interface{} err = json.Unmarshal(b, &res) t.Log(err) }
Successful test, the JSON is valid.
unexpected end of JSON input
The error is from inside the json decoder. If I change the test to
var res interface{} err = json.NewDecoder(resp.Body).Decode(&res) t.Log(err)
the error changes to
EOF
Stepping through the original test I can see that the io.ReadAlls result is already empty which it probably shouldn't be?
io.ReadAll
The text was updated successfully, but these errors were encountered:
It does help to use Fprintln here...
Fprintln
Sorry, something went wrong.
So what did you end up doing? Getting a similar issue and causing one of my tests to be flaky.
@pgarneau please open a new issue
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Testing an http client doing JSON request using
httptest
my test always failed.This is the test:
What did you expect to see?
Successful test, the JSON is valid.
What did you see instead?
The error is from inside the json decoder. If I change the test to
the error changes to
Stepping through the original test I can see that the
io.ReadAll
s result is already empty which it probably shouldn't be?The text was updated successfully, but these errors were encountered: