f580d88a14
gates / gates (push) Successful in 45s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
43 lines
1.5 KiB
Go
43 lines
1.5 KiB
Go
package stacks
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
// R-1028/R-1045: Plex's „claimed" can be probed only with Accept: application/json (it answers XML otherwise —
|
|
// measured 2026-10-15 on Tester 1). The probe with `accept:` reads the JSON field; without it the same server reads
|
|
// „not JSON" and the gate stays closed. COMPANION RED-PROOF: ignore p.Accept in probeOnce → the first case fails.
|
|
func TestSetupDoneProbe_AcceptJSON_Plex(t *testing.T) {
|
|
claimed := false
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
c := "0"
|
|
if claimed {
|
|
c = "1"
|
|
}
|
|
if r.Header.Get("Accept") == "application/json" {
|
|
v := "false"
|
|
if claimed {
|
|
v = "true"
|
|
}
|
|
_, _ = w.Write([]byte(`{"MediaContainer":{"size":0,"claimed":` + v + `}}`))
|
|
return
|
|
}
|
|
_, _ = w.Write([]byte(`<?xml version="1.0"?><MediaContainer size="0" claimed="` + c + `"></MediaContainer>`))
|
|
}))
|
|
defer srv.Close()
|
|
p := &SetupDoneProbe{URL: srv.URL + "/identity", Field: "MediaContainer.claimed", Done: "true", Accept: "application/json"}
|
|
if done, got, err := probeOnce(p); err != nil || done {
|
|
t.Fatalf("an unclaimed Plex must read NOT done: done=%v got=%q err=%v", done, got, err)
|
|
}
|
|
claimed = true
|
|
if done, got, err := probeOnce(p); err != nil || !done {
|
|
t.Fatalf("a claimed Plex must read done: done=%v got=%q err=%v", done, got, err)
|
|
}
|
|
p.Accept = ""
|
|
if done, got, _ := probeOnce(p); done || got != "not JSON" {
|
|
t.Fatalf("without the Accept header Plex answers XML: done=%v got=%q", done, got)
|
|
}
|
|
}
|