feat: proxy PreZero priority endpoints to FastAPI
ci / check (push) Successful in 58s
ci / check (pull_request) Successful in 55s

This commit is contained in:
Noel Sabia committed 2026-11-14 17:50:53 +01:00
1 parent a0ad60ec53
commit 7e9c2d9663
5 files changed
+564 -11

No files matched your search

+68
View File
@@ -305,3 +305,71 @@ func TestTrainStatusForwardsJobIDAndUpstreamError(t *testing.T) {
t.Fatalf("status=%d body=%s, want forwarded 404", status, body)
}
}
func TestPreZeroClientsForwardRouteQueryAndStatus(t *testing.T) {
var gotPaths, gotQueries []string
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
t.Errorf("method=%s, want GET", r.Method)
}
gotPaths = append(gotPaths, r.URL.Path)
gotQueries = append(gotQueries, r.URL.RawQuery)
switch {
case r.URL.Path == "/prezero/summary":
_, _ = w.Write([]byte(`{"summary":{"priority_counts":{"high":88}}}`))
case r.URL.Path == "/prezero/priority":
_, _ = w.Write([]byte(`{"total":88,"count":1,"containers":[]}`))
case r.URL.Path == "/prezero/containers/known-id":
_, _ = w.Write([]byte(`{"container":{"location_id":"known-id"}}`))
default:
w.WriteHeader(http.StatusNotFound)
_, _ = w.Write([]byte(`{"error":{"code":"not_found","message":"container not found"}}`))
}
}))
defer srv.Close()
client := New(srv.URL, time.Second)
status, body, err := client.PreZeroSummary(context.Background())
if err != nil || status != http.StatusOK || !strings.Contains(string(body), `"high":88`) {
t.Fatalf("summary status=%d body=%s err=%v", status, body, err)
}
status, body, err = client.PreZeroPriority(context.Background(), "high", 3, 10)
if err != nil || status != http.StatusOK || !strings.Contains(string(body), `"total":88`) {
t.Fatalf("priority status=%d body=%s err=%v", status, body, err)
}
if _, _, err := client.PreZeroPriority(context.Background(), "", 50, 0); err != nil {
t.Fatalf("priority defaults: %v", err)
}
status, body, err = client.PreZeroContainer(context.Background(), "known-id")
if err != nil || status != http.StatusOK || !strings.Contains(string(body), "known-id") {
t.Fatalf("container status=%d body=%s err=%v", status, body, err)
}
status, body, err = client.PreZeroContainer(context.Background(), "missing")
if err != nil {
t.Fatalf("container missing: %v", err)
}
if status != http.StatusNotFound || !strings.Contains(string(body), "container not found") {
t.Fatalf("container missing status=%d body=%s, want forwarded 404", status, body)
}
wantPaths := []string{
"/prezero/summary",
"/prezero/priority",
"/prezero/priority",
"/prezero/containers/known-id",
"/prezero/containers/missing",
}
for i, want := range wantPaths {
if gotPaths[i] != want {
t.Errorf("request %d path=%q, want %q", i, gotPaths[i], want)
}
}
wantQueries := []string{"", "limit=3&offset=10&priority=high", "limit=50&offset=0", "", ""}
for i, want := range wantQueries {
if gotQueries[i] != want {
t.Errorf("request %d query=%q, want %q", i, gotQueries[i], want)
}
}
}