]> Cypherpunks repositories - gostls13.git/commitdiff
http: run tests even with DISABLE_NET_TESTS=1
authorBrad Fitzpatrick <bradfitz@golang.org>
Thu, 10 Mar 2011 18:19:11 +0000 (10:19 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 10 Mar 2011 18:19:11 +0000 (10:19 -0800)
All tests are now localhost only.

R=rsc
CC=golang-dev
https://golang.org/cl/4271042

src/pkg/Makefile
src/pkg/http/request_test.go

index 062f7e587464f70b850df73caa98617d2171bb22..31d7e1a68214b7b087d05a62e97b8c48ab66e2a3 100644 (file)
@@ -200,7 +200,7 @@ NOBENCH=\
 
 # Disable tests that depend on an external network.
 ifeq ($(DISABLE_NET_TESTS),1)
-NOTEST+=http net syslog
+NOTEST+=net syslog
 endif
 
 # Disable tests that windows cannot run yet.
index ae1c4e98245212f9d48d1d2c28f843d99405966c..19083adf624ee72bb209922ca9e63ed1d833969f 100644 (file)
@@ -2,10 +2,15 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-package http
+package http_test
 
 import (
        "bytes"
+       "fmt"
+       . "http"
+       "http/httptest"
+       "io"
+       "os"
        "reflect"
        "regexp"
        "strings"
@@ -141,17 +146,33 @@ func TestMultipartReader(t *testing.T) {
 }
 
 func TestRedirect(t *testing.T) {
-       const (
-               start = "http://google.com/"
-               endRe = "^http://www\\.google\\.[a-z.]+/$"
-       )
-       var end = regexp.MustCompile(endRe)
-       r, url, err := Get(start)
+       ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
+               switch r.URL.Path {
+               case "/":
+                       w.Header().Set("Location", "/foo/")
+                       w.WriteHeader(StatusSeeOther)
+               case "/foo/":
+                       fmt.Fprintf(w, "foo")
+               default:
+                       w.WriteHeader(StatusBadRequest)
+               }
+       }))
+       defer ts.Close()
+
+       var end = regexp.MustCompile("/foo/$")
+       r, url, err := Get(ts.URL)
        if err != nil {
                t.Fatal(err)
        }
        r.Body.Close()
        if r.StatusCode != 200 || !end.MatchString(url) {
-               t.Fatalf("Get(%s) got status %d at %q, want 200 matching %q", start, r.StatusCode, url, endRe)
+               t.Fatalf("Get got status %d at %q, want 200 matching /foo/$", r.StatusCode, url)
        }
 }
+
+// TODO: stop copy/pasting this around.  move to io/ioutil?
+type nopCloser struct {
+       io.Reader
+}
+
+func (nopCloser) Close() os.Error { return nil }