From 6da048344775e2002ddf447d0dab104b119d9f1c Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Fri, 23 Feb 2018 22:32:27 +0300 Subject: [PATCH] [FIX] We must close gzip.Reader, only if no error (#1069) * [FIX] We must close gzip.Reader, only if no error * review comments fix --- middleware/compress_test.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/middleware/compress_test.go b/middleware/compress_test.go index d9661cd9..56bcf468 100644 --- a/middleware/compress_test.go +++ b/middleware/compress_test.go @@ -89,12 +89,13 @@ func TestGzipWithStatic(t *testing.T) { assert.Equal(t, cl, rec.Body.Len()) } r, err := gzip.NewReader(rec.Body) - assert.NoError(t, err) - defer r.Close() - want, err := ioutil.ReadFile("../_fixture/images/walle.png") if assert.NoError(t, err) { - buf := new(bytes.Buffer) - buf.ReadFrom(r) - assert.Equal(t, want, buf.Bytes()) + defer r.Close() + want, err := ioutil.ReadFile("../_fixture/images/walle.png") + if assert.NoError(t, err) { + buf := new(bytes.Buffer) + buf.ReadFrom(r) + assert.Equal(t, want, buf.Bytes()) + } } }