Skip to content

Commit

Permalink
rewrite TestGetContentCustom to work offline
Browse files Browse the repository at this point in the history
  • Loading branch information
paskal committed Nov 16, 2023
1 parent d681d21 commit f8a253f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions backend/extractor/readability_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,26 @@ func (m RulesMock) All(_ context.Context) []datastore.Rule { retu
func TestGetContentCustom(t *testing.T) {
lr := UReadability{TimeOut: 30, SnippetSize: 200, Rules: RulesMock{}}
httpClient := &http.Client{Timeout: time.Second * 30}
resp, err := httpClient.Get("https://p.umputun.com/2015/09/25/poiezdka-s-apple-maps/")
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.URL.String() == "/2015/09/25/poiezdka-s-apple-maps/" {
fh, err := os.Open("testdata/poiezdka-s-apple-maps.html")
testHTML, err := io.ReadAll(fh)
assert.NoError(t, err)
assert.NoError(t, fh.Close())
_, err = w.Write(testHTML)
assert.NoError(t, err)
return
}
}))
defer ts.Close()
resp, err := httpClient.Get(ts.URL + "/2015/09/25/poiezdka-s-apple-maps/")
assert.NoError(t, err)
defer resp.Body.Close()
dataBytes, err := io.ReadAll(resp.Body)
assert.NoError(t, err)
body := string(dataBytes)

content, rich, err := lr.getContent(context.Background(), body, "https://p.umputun.com/2015/09/25/poiezdka-s-apple-maps/")
content, rich, err := lr.getContent(context.Background(), body, ts.URL+"/2015/09/25/poiezdka-s-apple-maps/")
assert.NoError(t, err)
assert.Equal(t, 6988, len(content))
assert.Equal(t, 7169, len(rich))
Expand Down

0 comments on commit f8a253f

Please sign in to comment.