Jelajahi Sumber

test(readability): add test case for `ExtractContent` with broken reader

Frédéric Guillot 1 tahun lalu
induk
melakukan
8c3f280f32

+ 2 - 2
internal/reader/readability/readability.go

@@ -400,8 +400,8 @@ func transformMisusedDivsIntoParagraphs(document *goquery.Document) {
 				"table", "ul":
 				return
 			default:
-				node := s.Get(0)
-				node.Data = "p"
+				currentNode := s.Get(0)
+				currentNode.Data = "p"
 			}
 		}
 	})

+ 13 - 0
internal/reader/readability/readability_test.go

@@ -2479,3 +2479,16 @@ func TestCandidateStringEdgeCases(t *testing.T) {
 		}
 	})
 }
+
+func TestExtractContentWithBrokenReader(t *testing.T) {
+	if _, _, err := ExtractContent(&brokenReader{}); err == nil {
+		t.Error("Expected ExtractContent to return an error with broken reader")
+	}
+}
+
+// brokenReader implements io.Reader but always returns an error
+type brokenReader struct{}
+
+func (br *brokenReader) Read(p []byte) (n int, err error) {
+	return 0, fmt.Errorf("simulated read error")
+}