From: Brad Fitzpatrick Date: Thu, 10 Mar 2011 16:46:57 +0000 (-0800) Subject: http: don't hit external network in client_test.go X-Git-Tag: weekly.2011-03-15~50 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=8e1fa76047e93bf2816520af52759137972a534f;p=gostls13.git http: don't hit external network in client_test.go More reliable. R=rsc CC=golang-dev https://golang.org/cl/4249068 --- diff --git a/src/pkg/http/client_test.go b/src/pkg/http/client_test.go index c89ecbce2d..3d71707881 100644 --- a/src/pkg/http/client_test.go +++ b/src/pkg/http/client_test.go @@ -4,20 +4,28 @@ // Tests for client.go -package http +package http_test import ( + "fmt" + . "http" + "http/httptest" "io/ioutil" "os" "strings" "testing" ) +var robotsTxtHandler = HandlerFunc(func(w ResponseWriter, r *Request) { + w.Header().Set("Last-Modified", "sometime") + fmt.Fprintf(w, "User-agent: go\nDisallow: /something/") +}) + func TestClient(t *testing.T) { - // TODO: add a proper test suite. Current test merely verifies that - // we can retrieve the Google robots.txt file. + ts := httptest.NewServer(robotsTxtHandler) + defer ts.Close() - r, _, err := Get("http://www.google.com/robots.txt") + r, _, err := Get(ts.URL) var b []byte if err == nil { b, err = ioutil.ReadAll(r.Body) @@ -31,7 +39,10 @@ func TestClient(t *testing.T) { } func TestClientHead(t *testing.T) { - r, err := Head("http://www.google.com/robots.txt") + ts := httptest.NewServer(robotsTxtHandler) + defer ts.Close() + + r, err := Head(ts.URL) if err != nil { t.Fatal(err) }