From: Brad Fitzpatrick Date: Thu, 9 Feb 2012 05:45:24 +0000 (+1100) Subject: net/http/httptest: add a test X-Git-Tag: weekly.2012-02-14~187 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ce57ba9feec078191db2873017bd63f996afd835;p=gostls13.git net/http/httptest: add a test Less ironic. Don't you think? R=golang-dev, rsc CC=golang-dev https://golang.org/cl/5643069 --- diff --git a/src/pkg/net/http/httptest/server_test.go b/src/pkg/net/http/httptest/server_test.go new file mode 100644 index 0000000000..500a9f0b80 --- /dev/null +++ b/src/pkg/net/http/httptest/server_test.go @@ -0,0 +1,29 @@ +// 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)) + } +}