@@ -5,25 +5,14 @@ import (
5
5
"fmt"
6
6
"net/http"
7
7
"net/http/httptest"
8
+ "strconv"
8
9
"strings"
9
10
"testing"
10
11
)
11
12
12
13
//go:embed testdata
13
14
var testdata embed.FS
14
15
15
- type test struct {
16
- Path string
17
- Method string
18
- AE string
19
-
20
- Status int
21
- CE string
22
- Vary string
23
- }
24
-
25
- const AE = "Accept-Encoding"
26
-
27
16
var methods = []string {"GET" , "HEAD" }
28
17
var paths = map [string ]string {
29
18
"testdata/static/js/2.js" : "text/javascript; charset=UTF-8" ,
@@ -82,12 +71,24 @@ func TestOK(t *testing.T) {
82
71
for acceptEncoding , contentEncoding := range encodings {
83
72
t .Run (fmt .Sprintf ("%s %s %s" , method , path , acceptEncoding ), func (t * testing.T ) {
84
73
r := httptest .NewRecorder ()
74
+
85
75
mux .ServeHTTP (r , newRequest (t , method , srIndex [path ], acceptEncoding ))
76
+
86
77
assertStatus (t , http .StatusOK , r .Code )
87
78
if r .Code == http .StatusOK {
88
79
assertEqualFold (t , "Content-Type" , contentType , r .Header ().Get ("Content-Type" ))
89
80
assertEqualFold (t , "Content-Encoding" , contentEncoding , r .Header ().Get ("Content-Encoding" ))
90
81
assertEqualFold (t , "Vary" , "Accept-Encoding" , r .Header ().Get ("Vary" ))
82
+ switch method {
83
+ case http .MethodGet :
84
+ contentLength , err := strconv .Atoi (r .Header ().Get ("Content-Length" ))
85
+ if err != nil {
86
+ t .Errorf ("failed to parse Content-Length: %v" , err )
87
+ }
88
+ assert (t , "body length" , r .Body .Len (), contentLength )
89
+ case http .MethodHead :
90
+ assert (t , "body length" , r .Body .Len (), 0 )
91
+ }
91
92
}
92
93
})
93
94
}
0 commit comments