Sync shared snapshot from 097442f
Docker / Docker Build & Push (push) Successful in 3m20s

This commit is contained in:
Gabriel20xx committed 2026-09-11 11:57:31 +02:00
1 parent a2a96f6a46
commit 439ef02496
2 files changed
+96 -31

No files matched your search

@@ -105,7 +105,7 @@ func TestProbeExistsFalseWhenNoInstanceHasFile(t *testing.T) {
}
}
func TestProxyAlwaysTargetsPrimaryInstance(t *testing.T) {
func TestProxyPrefersPrimaryInstanceWhenItHasTheFile(t *testing.T) {
var primaryHit, secondaryHit bool
primary := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
primaryHit = true
@@ -128,6 +128,49 @@ func TestProxyAlwaysTargetsPrimaryInstance(t *testing.T) {
t.Fatal("Proxy did not hit the primary instance")
}
if secondaryHit {
t.Fatal("Proxy hit the secondary instance, want primary-only")
t.Fatal("Proxy hit the secondary instance even though the primary had the file")
}
}
func TestProxyFallsBackToSecondaryInstanceWhenPrimaryMisses(t *testing.T) {
primary := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
defer primary.Close()
secondary := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "video/mp4")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("video bytes"))
}))
defer secondary.Close()
client := NewMulti("", func(ctx context.Context) []string { return []string{primary.URL, secondary.URL} })
req := httptest.NewRequest(http.MethodGet, "/media/a.mp4", nil)
rec := httptest.NewRecorder()
client.Proxy(rec, req, "/media/a.mp4")
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, want 200 from the secondary instance", rec.Code)
}
if rec.Body.String() != "video bytes" {
t.Fatalf("body = %q, want secondary instance's bytes", rec.Body.String())
}
}
func TestProxyForwardsLastInstanceErrorWhenNoneHaveTheFile(t *testing.T) {
notFound := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNotFound)
}))
defer notFound.Close()
client := NewMulti("", func(ctx context.Context) []string { return []string{notFound.URL, notFound.URL} })
req := httptest.NewRequest(http.MethodGet, "/media/missing.mp4", nil)
rec := httptest.NewRecorder()
client.Proxy(rec, req, "/media/missing.mp4")
if rec.Code != http.StatusNotFound {
t.Fatalf("status = %d, want 404 forwarded from the last instance", rec.Code)
}
}