Synthetic full editorial body.
package articlecontent
import (
"context"
"github.com/tradarr/backend/internal/scraper"
"io"
"net/http"
"strings"
"testing"
)
func TestObservedYahooRedirectIdentities(t *testing.T) {
initial := "https://finance.yahoo.com/news/fixture-initial.html"
final := "https://finance.yahoo.com/news/fixture-final.html"
for _, tc := range []struct {
name, destination, identity string
complete bool
}{
{"canonical_initial", final, initial, true}, {"canonical_final", final, final, true},
{"unobserved", final, "https://finance.yahoo.com/news/fixture-other.html", false},
{"third_party_identity", final, "https://example.invalid/fixture.html", false},
{"external_redirect", "https://example.invalid/fixture.html", initial, false},
{"upgrade_before_fetch", "http://finance.yahoo.com/news/fixture-final.html", initial, true},
} {
for _, metadata := range []string{"canonical", "NewsArticle"} {
t.Run(tc.name+metadata, func(t *testing.T) {
calls := 0
client := &http.Client{Transport: roundTrip(func(r *http.Request) (*http.Response, error) {
calls++
h := make(http.Header)
status := 200
body := ""
if calls == 1 {
status = 302
h.Set("Location", tc.destination)
} else {
if r.URL.String() != final {
t.Fatal("untrusted redirect fetched")
}
body = ``
if metadata == "NewsArticle" {
body = ``
}
body += ` Synthetic full editorial body.
Synthetic complete editorial body.