Skip to content

Commit d0729a6

Browse files
committed
encoding/json: test style tweaks
Rename test name from Http to HTTP, and fix some style nits. Change-Id: I00fe1cecd69ca2f50be86a76ec90031c2f921707 Reviewed-on: https://go-review.googlesource.com/12760 Reviewed-by: Andrew Gerrand <adg@golang.org>
1 parent deaf033 commit d0729a6

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed

src/encoding/json/stream_test.go

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -319,43 +319,36 @@ func TestDecodeInStream(t *testing.T) {
319319

320320
}
321321

322-
const raw = `{ "foo": "bar" }`
322+
// Test from golang.org/issue/11893
323+
func TestHTTPDecoding(t *testing.T) {
324+
const raw = `{ "foo": "bar" }`
323325

324-
func makeHTTP() io.ReadCloser {
325-
mux := http.NewServeMux()
326-
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
326+
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
327327
w.Write([]byte(raw))
328-
})
329-
ts := httptest.NewServer(mux)
328+
}))
330329
defer ts.Close()
331330
res, err := http.Get(ts.URL)
332331
if err != nil {
333332
log.Fatalf("GET failed: %v", err)
334333
}
335-
return res.Body
336-
}
337-
338-
func TestHttpDecoding(t *testing.T) {
334+
defer res.Body.Close()
339335

340336
foo := struct {
341337
Foo string
342338
}{}
343339

344-
rc := makeHTTP()
345-
defer rc.Close()
346-
347-
d := NewDecoder(rc)
348-
err := d.Decode(&foo)
340+
d := NewDecoder(res.Body)
341+
err = d.Decode(&foo)
349342
if err != nil {
350-
t.Errorf("Unexpected error %v", err)
343+
t.Fatalf("Decode: %v", err)
351344
}
352345
if foo.Foo != "bar" {
353-
t.Errorf("Expected \"bar\", was %v", foo.Foo)
346+
t.Errorf("decoded %q; want \"bar\"", foo.Foo)
354347
}
355348

356349
// make sure we get the EOF the second time
357350
err = d.Decode(&foo)
358351
if err != io.EOF {
359-
t.Errorf("Expected io.EOF, was %v", err)
352+
t.Errorf("err = %v; want io.EOF", err)
360353
}
361354
}

0 commit comments

Comments
 (0)