-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathregression_test.go
68 lines (56 loc) · 1.45 KB
/
regression_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 Jamie Hall. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package spdy_test
import (
"bytes"
"io"
"io/ioutil"
"net/http"
"testing"
"github.com/SlyMarbo/spdy/common"
)
func issue82handler(n int64) http.HandlerFunc {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write(bytes.Repeat([]byte{'X'}, int(n)))
})
}
func TestIssue82(t *testing.T) {
var max int64 = common.DEFAULT_INITIAL_CLIENT_WINDOW_SIZE
tests := []struct {
Name string
Path string
Msg string
Want int64
}{
{"Issue 82", "/1", "Sending less than window size", max - 16},
{"Issue 82", "/2", "Sending just under window size", max - 15},
{"Issue 82", "/3", "Sending exactly window size", max},
{"Issue 82", "/4", "Sending more than window size", max + 16},
}
// start server
mux := http.NewServeMux()
for _, test := range tests {
mux.HandleFunc(test.Path, issue82handler(test.Want))
}
srv := newServer(mux)
defer srv.Close()
client := newClient()
for _, test := range tests {
r, err := client.Get(srv.URL + test.Path)
if err != nil {
t.Fatal(err)
}
n, err := io.Copy(ioutil.Discard, r.Body)
if err != nil {
t.Fatal(err)
}
if err = r.Body.Close(); err != nil {
t.Fatal(err)
}
if n != test.Want {
t.Errorf("%s: %s, got %d, expected %d", test.Name, test.Msg, n, test.Want)
}
}
}