| index c68d18175..c5b27b3f1 100644 |
| --- a/internal/instancectl/claimunit_test.go |
| +++ b/internal/instancectl/claimunit_test.go |
| @@ -251,3 +251,27 @@ func TestClaimLaunchRouteExistsOnlyInClaimMode(t *testing.T) { |
| t.Fatalf("GET /claim/launch=%d", rec.Code) |
| } |
| } |
| + |
| +// TestClaimHeldReleaseRouteExistsOnlyInClaimMode (moves Task 7b): the |
| +// root's held-release route is the claim handler's, and a flag-off mux |
| +// has none, so an agent's request there reads as unavailable. |
| +func TestClaimHeldReleaseRouteExistsOnlyInClaimMode(t *testing.T) { |
| + legacy := (&Server{Systemctl: func(context.Context, ...string) (string, error) { return "", nil }}).Handler() |
| + rec := httptest.NewRecorder() |
| + legacy.ServeHTTP(rec, httptest.NewRequest(http.MethodPost, "/claim/held-release", strings.NewReader("{}"))) |
| + if rec.Code != http.StatusNotFound { |
| + t.Fatalf("flag-off mux answered /claim/held-release with %d", rec.Code) |
| + } |
| + reached := "" |
| + claim := (&Server{ClaimStop: http.HandlerFunc(func(_ http.ResponseWriter, r *http.Request) { reached = r.URL.Path })}).Handler() |
| + rec = httptest.NewRecorder() |
| + claim.ServeHTTP(rec, httptest.NewRequest(http.MethodPost, "/claim/held-release", strings.NewReader("{}"))) |
| + if reached != "/claim/held-release" { |
| + t.Fatalf("claim mux did not route /claim/held-release: %q", reached) |
| + } |
| + rec = httptest.NewRecorder() |
| + claim.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/claim/held-release", nil)) |
| + if rec.Code != http.StatusMethodNotAllowed { |
| + t.Fatalf("GET /claim/held-release=%d", rec.Code) |
| + } |
| +} |