Skip to content

Commit

Permalink
close response.Body in image proxy tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal authored and umputun committed Apr 24, 2020
1 parent b71e0be commit 5579bd1
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion backend/app/rest/proxy/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func gopherPNGBytes() []byte {
}

func TestImage_Extract(t *testing.T) {

tbl := []struct {
inp string
res []string
Expand Down Expand Up @@ -117,18 +116,21 @@ func TestImage_Routes(t *testing.T) {

resp, err := http.Get(ts.URL + "/?src=" + encodedImgURL)
require.NoError(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "1462", resp.Header["Content-Length"][0])
assert.Equal(t, "image/png", resp.Header["Content-Type"][0])

encodedImgURL = base64.URLEncoding.EncodeToString([]byte(httpSrv.URL + "/image/no-such-image.png"))
resp, err = http.Get(ts.URL + "/?src=" + encodedImgURL)
require.NoError(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusNotFound, resp.StatusCode)

encodedImgURL = base64.URLEncoding.EncodeToString([]byte(httpSrv.URL + "bad encoding"))
resp, err = http.Get(ts.URL + "/?src=" + encodedImgURL)
require.NoError(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
}

Expand All @@ -151,6 +153,7 @@ func TestImage_DisabledCachingAndHTTP2HTTPS(t *testing.T) {

resp, err := http.Get(ts.URL + "/?src=" + encodedImgURL)
require.NoError(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "1462", resp.Header["Content-Length"][0])
assert.Equal(t, "image/png", resp.Header["Content-Type"][0])
Expand Down Expand Up @@ -181,6 +184,7 @@ func TestImage_RoutesCachingImage(t *testing.T) {

resp, err := http.Get(ts.URL + "/?src=" + encodedImgURL)
require.Nil(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "1462", resp.Header["Content-Length"][0])
assert.Equal(t, "image/png", resp.Header["Content-Type"][0])
Expand Down Expand Up @@ -212,6 +216,7 @@ func TestImage_RoutesUsingCachedImage(t *testing.T) {

resp, err := http.Get(ts.URL + "/?src=" + encodedImgURL)
require.Nil(t, err)
assert.NoError(t, resp.Body.Close())
assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "256", resp.Header["Content-Length"][0])
assert.Equal(t, "text/plain; charset=utf-8", resp.Header["Content-Type"][0],
Expand Down Expand Up @@ -244,6 +249,7 @@ func TestImage_RoutesTimedOut(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
b, err := ioutil.ReadAll(resp.Body)
assert.NoError(t, resp.Body.Close())
require.NoError(t, err)
t.Log(string(b))
assert.True(t, strings.Contains(string(b), "deadline exceeded"))
Expand Down

0 comments on commit 5579bd1

Please sign in to comment.