| // Copyright 2012 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| func TestServer(t *testing.T) { |
| ts := NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| res, err := http.Get(ts.URL) |
| got, err := ioutil.ReadAll(res.Body) |
| if string(got) != "hello" { |
| t.Errorf("got %q, want hello", string(got)) |
| func TestGetAfterClose(t *testing.T) { |
| ts := NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| res, err := http.Get(ts.URL) |
| got, err := ioutil.ReadAll(res.Body) |
| if string(got) != "hello" { |
| t.Fatalf("got %q, want hello", string(got)) |
| res, err = http.Get(ts.URL) |
| body, _ := ioutil.ReadAll(res.Body) |
| t.Fatalf("Unexected response after close: %v, %v, %s", res.Status, res.Header, body) |