Commit ce57ba9f authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http/httptest: add a test

Less ironic. Don't you think?

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5643069
parent 5c52404a
// 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.
package httptest
import (
"io/ioutil"
"net/http"
"testing"
)
func TestServer(t *testing.T) {
ts := NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello"))
}))
defer ts.Close()
res, err := http.Get(ts.URL)
if err != nil {
t.Fatal(err)
}
got, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if string(got) != "hello" {
t.Errorf("got %q, want hello", string(got))
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment