mirror of
https://github.com/golang/go
synced 2024-11-23 19:30:05 -07:00
net/http: sniff tests ported to h2
Change-Id: Icad6cc130252ac177946b23c12f36d6ba3275bf0 Reviewed-on: https://go-review.googlesource.com/17436 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
2f2423c81d
commit
c2290feeeb
@ -52,9 +52,12 @@ func TestDetectContentType(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestServerContentType(t *testing.T) {
|
func TestServerContentType_h1(t *testing.T) { testServerContentType(t, false) }
|
||||||
|
func TestServerContentType_h2(t *testing.T) { testServerContentType(t, true) }
|
||||||
|
|
||||||
|
func testServerContentType(t *testing.T, h2 bool) {
|
||||||
defer afterTest(t)
|
defer afterTest(t)
|
||||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||||
i, _ := strconv.Atoi(r.FormValue("i"))
|
i, _ := strconv.Atoi(r.FormValue("i"))
|
||||||
tt := sniffTests[i]
|
tt := sniffTests[i]
|
||||||
n, err := w.Write(tt.data)
|
n, err := w.Write(tt.data)
|
||||||
@ -62,10 +65,10 @@ func TestServerContentType(t *testing.T) {
|
|||||||
log.Fatalf("%v: Write(%q) = %v, %v want %d, nil", tt.desc, tt.data, n, err, len(tt.data))
|
log.Fatalf("%v: Write(%q) = %v, %v want %d, nil", tt.desc, tt.data, n, err, len(tt.data))
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer cst.close()
|
||||||
|
|
||||||
for i, tt := range sniffTests {
|
for i, tt := range sniffTests {
|
||||||
resp, err := Get(ts.URL + "/?i=" + strconv.Itoa(i))
|
resp, err := cst.c.Get(cst.ts.URL + "/?i=" + strconv.Itoa(i))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%v: %v", tt.desc, err)
|
t.Errorf("%v: %v", tt.desc, err)
|
||||||
continue
|
continue
|
||||||
@ -106,7 +109,10 @@ func TestServerIssue5953(t *testing.T) {
|
|||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestContentTypeWithCopy(t *testing.T) {
|
func TestContentTypeWithCopy_h1(t *testing.T) { testContentTypeWithCopy(t, false) }
|
||||||
|
func TestContentTypeWithCopy_h2(t *testing.T) { testContentTypeWithCopy(t, true) }
|
||||||
|
|
||||||
|
func testContentTypeWithCopy(t *testing.T, h2 bool) {
|
||||||
defer afterTest(t)
|
defer afterTest(t)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -114,7 +120,7 @@ func TestContentTypeWithCopy(t *testing.T) {
|
|||||||
expected = "text/html; charset=utf-8"
|
expected = "text/html; charset=utf-8"
|
||||||
)
|
)
|
||||||
|
|
||||||
ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {
|
cst := newClientServerTest(t, h2, HandlerFunc(func(w ResponseWriter, r *Request) {
|
||||||
// Use io.Copy from a bytes.Buffer to trigger ReadFrom.
|
// Use io.Copy from a bytes.Buffer to trigger ReadFrom.
|
||||||
buf := bytes.NewBuffer([]byte(input))
|
buf := bytes.NewBuffer([]byte(input))
|
||||||
n, err := io.Copy(w, buf)
|
n, err := io.Copy(w, buf)
|
||||||
@ -122,9 +128,9 @@ func TestContentTypeWithCopy(t *testing.T) {
|
|||||||
t.Errorf("io.Copy(w, %q) = %v, %v want %d, nil", input, n, err, len(input))
|
t.Errorf("io.Copy(w, %q) = %v, %v want %d, nil", input, n, err, len(input))
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
defer ts.Close()
|
defer cst.close()
|
||||||
|
|
||||||
resp, err := Get(ts.URL)
|
resp, err := cst.c.Get(cst.ts.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Get: %v", err)
|
t.Fatalf("Get: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user