@@ -26,13 +26,8 @@ func TestCompressor(t *testing.T) {
26
26
return w
27
27
})
28
28
29
- var sideEffect int
30
- compressor .SetEncoder ("test" , func (w io.Writer , _ int ) io.Writer {
31
- return newSideEffectWriter (w , & sideEffect )
32
- })
33
-
34
- if len (compressor .encoders ) != 2 {
35
- t .Errorf ("nop and test encoders should be stored in the encoders map" )
29
+ if len (compressor .encoders ) != 1 {
30
+ t .Errorf ("nop encoder should be stored in the encoders map" )
36
31
}
37
32
38
33
r .Use (compressor .Handler )
@@ -52,11 +47,6 @@ func TestCompressor(t *testing.T) {
52
47
w .Write ([]byte ("textstring" ))
53
48
})
54
49
55
- r .Get ("/getimage" , func (w http.ResponseWriter , r * http.Request ) {
56
- w .Header ().Set ("Content-Type" , "image/png" )
57
- w .Write ([]byte ("textstring" ))
58
- })
59
-
60
50
ts := httptest .NewServer (r )
61
51
defer ts .Close ()
62
52
@@ -103,12 +93,6 @@ func TestCompressor(t *testing.T) {
103
93
acceptedEncodings : []string {"nop, gzip, deflate" },
104
94
expectedEncoding : "nop" ,
105
95
},
106
- {
107
- name : "test is used and side effect is cleared after close" ,
108
- path : "/getimage" ,
109
- acceptedEncodings : []string {"test" },
110
- expectedEncoding : "" ,
111
- },
112
96
}
113
97
114
98
for _ , tc := range tests {
@@ -123,10 +107,7 @@ func TestCompressor(t *testing.T) {
123
107
}
124
108
125
109
})
126
- }
127
110
128
- if sideEffect > 1 {
129
- t .Errorf ("side effect should be cleared after close" )
130
111
}
131
112
}
132
113
@@ -236,26 +217,3 @@ func decodeResponseBody(t *testing.T, resp *http.Response) string {
236
217
237
218
return string (respBody )
238
219
}
239
-
240
- type (
241
- sideEffectWriter struct {
242
- w io.Writer
243
- s * int
244
- }
245
- )
246
-
247
- func newSideEffectWriter (w io.Writer , sideEffect * int ) io.Writer {
248
- * sideEffect = * sideEffect + 1
249
-
250
- return & sideEffectWriter {w : w , s : sideEffect }
251
- }
252
-
253
- func (w * sideEffectWriter ) Write (p []byte ) (n int , err error ) {
254
- return w .w .Write (p )
255
- }
256
-
257
- func (w * sideEffectWriter ) Close () error {
258
- * w .s = * w .s - 1
259
-
260
- return nil
261
- }
0 commit comments