|
|
@@ -4,11 +4,26 @@
|
|
|
package fetcher // import "miniflux.app/v2/internal/reader/fetcher"
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
+ "io"
|
|
|
"net/http"
|
|
|
"testing"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+type testReadCloser struct {
|
|
|
+ closed bool
|
|
|
+}
|
|
|
+
|
|
|
+func (rc *testReadCloser) Read(_ []byte) (int, error) {
|
|
|
+ return 0, io.EOF
|
|
|
+}
|
|
|
+
|
|
|
+func (rc *testReadCloser) Close() error {
|
|
|
+ rc.closed = true
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func TestIsModified(t *testing.T) {
|
|
|
var cachedEtag = "abc123"
|
|
|
var cachedLastModified = "Wed, 21 Oct 2015 07:28:00 GMT"
|
|
|
@@ -174,3 +189,17 @@ func TestCacheControlMaxAgeInMinutes(t *testing.T) {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func TestResponseHandlerCloseClosesBodyOnClientError(t *testing.T) {
|
|
|
+ body := &testReadCloser{}
|
|
|
+ rh := ResponseHandler{
|
|
|
+ httpResponse: &http.Response{Body: body},
|
|
|
+ clientErr: errors.New("boom"),
|
|
|
+ }
|
|
|
+
|
|
|
+ rh.Close()
|
|
|
+
|
|
|
+ if !body.closed {
|
|
|
+ t.Error("Expected response body to be closed")
|
|
|
+ }
|
|
|
+}
|