@@ -176,8 +176,7 @@ func Test_Static_Options(t *testing.T) {
176
176
})
177
177
178
178
Convey ("Serve static files with options expires" , t , func () {
179
- var buf bytes.Buffer
180
- m := NewWithLogger (& buf )
179
+ m := New ()
181
180
opt := StaticOptions {Expires : func () string { return "46" }}
182
181
m .Use (Static (currentRoot , opt ))
183
182
@@ -190,8 +189,7 @@ func Test_Static_Options(t *testing.T) {
190
189
})
191
190
192
191
Convey ("Serve static files with options ETag" , t , func () {
193
- var buf bytes.Buffer
194
- m := NewWithLogger (& buf )
192
+ m := New ()
195
193
opt := StaticOptions {ETag : true }
196
194
m .Use (Static (currentRoot , opt ))
197
195
@@ -203,6 +201,26 @@ func Test_Static_Options(t *testing.T) {
203
201
204
202
So (resp .Header ().Get ("ETag" ), ShouldEqual , `"` + tag + `"` )
205
203
})
204
+
205
+ Convey ("Serve static files with ETag in If-None-Match" , t , func () {
206
+ m := New ()
207
+ opt := StaticOptions {ETag : true }
208
+ m .Use (Static (currentRoot , opt ))
209
+
210
+ resp := httptest .NewRecorder ()
211
+ req , err := http .NewRequest ("GET" , "http://localhost:4000/macaron.go" , nil )
212
+ So (err , ShouldBeNil )
213
+ m .ServeHTTP (resp , req )
214
+ tag := GenerateETag (string (resp .Body .Len ()), "macaron.go" , resp .Header ().Get ("last-modified" ))
215
+
216
+ // Second request with ETag in If-None-Match
217
+ resp = httptest .NewRecorder ()
218
+ req .Header .Add ("If-None-Match" , `"` + tag + `"` )
219
+ m .ServeHTTP (resp , req )
220
+
221
+ So (resp .Code , ShouldEqual , http .StatusNotModified )
222
+ So (len (resp .Body .Bytes ()), ShouldEqual , 0 )
223
+ })
206
224
}
207
225
208
226
func Test_Static_Redirect (t * testing.T ) {
0 commit comments