Commit bbad6900 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http: run tests even with DISABLE_NET_TESTS=1

All tests are now localhost only.

R=rsc
CC=golang-dev
https://golang.org/cl/4271042
parent 8e1fa760
...@@ -200,7 +200,7 @@ NOBENCH=\ ...@@ -200,7 +200,7 @@ NOBENCH=\
# Disable tests that depend on an external network. # Disable tests that depend on an external network.
ifeq ($(DISABLE_NET_TESTS),1) ifeq ($(DISABLE_NET_TESTS),1)
NOTEST+=http net syslog NOTEST+=net syslog
endif endif
# Disable tests that windows cannot run yet. # Disable tests that windows cannot run yet.
......
...@@ -2,10 +2,15 @@ ...@@ -2,10 +2,15 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package http package http_test
import ( import (
"bytes" "bytes"
"fmt"
. "http"
"http/httptest"
"io"
"os"
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
...@@ -141,17 +146,33 @@ func TestMultipartReader(t *testing.T) { ...@@ -141,17 +146,33 @@ func TestMultipartReader(t *testing.T) {
} }
func TestRedirect(t *testing.T) { func TestRedirect(t *testing.T) {
const ( ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
start = "http://google.com/" switch r.URL.Path {
endRe = "^http://www\\.google\\.[a-z.]+/$" case "/":
) w.Header().Set("Location", "/foo/")
var end = regexp.MustCompile(endRe) w.WriteHeader(StatusSeeOther)
r, url, err := Get(start) 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 { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
r.Body.Close() r.Body.Close()
if r.StatusCode != 200 || !end.MatchString(url) { 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 }
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