Deprecate legacy VM inventory endpoints and add gating logic
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-13 14:59:19 +11:00
parent 18be1fbe06
commit 1f39b46613
5 changed files with 68 additions and 7 deletions

View File

@@ -67,3 +67,49 @@ func TestVmCreateEventHonorsLegacyGate(t *testing.T) {
}
})
}
func TestLegacyInventoryEndpointsAreGatedWhenDisabled(t *testing.T) {
h := newLegacyGateHandler(false)
cases := []struct {
name string
method string
path string
body string
call func(*Handler, *httptest.ResponseRecorder, *http.Request)
}{
{
name: "import vm",
method: http.MethodPost,
path: "/api/import/vm",
body: `{"name":"vm1"}`,
call: func(h *Handler, rr *httptest.ResponseRecorder, req *http.Request) { h.VmImport(rr, req) },
},
{
name: "cleanup vm",
method: http.MethodDelete,
path: "/api/inventory/vm/delete?vm_id=vm-1&datacenter_name=dc1",
call: func(h *Handler, rr *httptest.ResponseRecorder, req *http.Request) { h.VmCleanup(rr, req) },
},
{
name: "update vm details",
method: http.MethodPost,
path: "/api/inventory/vm/update",
call: func(h *Handler, rr *httptest.ResponseRecorder, req *http.Request) { h.VmUpdateDetails(rr, req) },
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
req := httptest.NewRequest(tc.method, tc.path, strings.NewReader(tc.body))
rr := httptest.NewRecorder()
tc.call(h, rr, req)
if rr.Code != http.StatusGone {
t.Fatalf("expected %d, got %d", http.StatusGone, rr.Code)
}
if !strings.Contains(rr.Body.String(), "deprecated") {
t.Fatalf("expected deprecated response, got: %s", rr.Body.String())
}
})
}
}