package request_test import ( "bytes" "io" "net/http" "testing" "github.com/moby/moby/v2/internal/testutil/request" "gotest.tools/v3/assert" ) func TestReadJSONResponse(t *testing.T) { type someResponse struct { Hello string `json:"Hello"` } tests := []struct { name string body string contentType string expected someResponse expErr string }{ { name: "valid JSON", body: `{"hello": "world"}`, contentType: "application/json", expected: someResponse{Hello: "world"}, }, { name: "valid JSON, utf-8", body: `{"hello": "world"}`, contentType: "application/json; charset=utf-8", expected: someResponse{Hello: "world"}, }, { name: "malformed JSON", body: `{"hello": "world"`, contentType: "application/json", expErr: "unexpected EOF", }, { name: "non-JSON", body: `