Posters: fall back to the provider's image when the instance has no copy
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -94,3 +94,33 @@ func TestResolveURLBase(t *testing.T) {
|
||||
t.Errorf("no url base: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPosterFallsBackToTheProviderWhenTheInstanceHasNoCopy(t *testing.T) {
|
||||
var remoteKey string
|
||||
remote := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
remoteKey = r.Header.Get("X-Api-Key")
|
||||
w.Write([]byte("REMOTE"))
|
||||
}))
|
||||
defer remote.Close()
|
||||
instance := httptest.NewServer(http.NotFoundHandler()) // MediaCover has nothing cached
|
||||
defer instance.Close()
|
||||
|
||||
c := NewClient(instance.URL, "secret")
|
||||
_, fetch, ok := c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/9/poster.jpg", RemoteURL: remote.URL + "/p.jpg"}}, true)
|
||||
if !ok {
|
||||
t.Fatal("no poster")
|
||||
}
|
||||
data, err := fetch(context.Background())
|
||||
if err != nil || string(data) != "REMOTE" {
|
||||
t.Fatalf("data=%q err=%v", data, err)
|
||||
}
|
||||
if remoteKey != "" {
|
||||
t.Errorf("the API key went to the provider: %q", remoteKey)
|
||||
}
|
||||
|
||||
// Without a remote address the local failure is reported.
|
||||
_, fetch, _ = c.Poster([]Image{{CoverType: "poster", URL: "/MediaCover/9/poster.jpg"}}, true)
|
||||
if _, err := fetch(context.Background()); err == nil {
|
||||
t.Error("expected the local error")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user